OpenDaVINCI  4.16.0
odcore::io::protocol::NetstringsProtocol Class Reference

#include <NetstringsProtocol.h>

Inheritance diagram for odcore::io::protocol::NetstringsProtocol:
Inheritance graph

Public Member Functions

 NetstringsProtocol ()
 
virtual ~NetstringsProtocol ()
 
void send (const string &data)
 
void setStringListener (StringListener *listener)
 
virtual void nextString (const string &s)
 
void setStringSender (StringSender *sender)
 
void sendByStringSender (const string &data)
 

Detailed Description

This class realizes a thread-safe Netstrings protocol implementation.

It can be used as follows:

// Your class needs to implement the interface StringListener to get
// informed about newly received payloads extracted from a Netstring.
np.setStringListener(this); // We are listening for byte sequences.
np.setStringSender(<your sender, could be your class that receives the Netstrings encoded data>);
...
// Your byte sequence receiving thread triggering the Netstrings decoding:
np.nextString(partialData);
...
// Encoding a byte sequence as a Netstring.
string payload = "Hello World!";
np.send(payload);

Constructor & Destructor Documentation

odcore::io::protocol::NetstringsProtocol::NetstringsProtocol ( )

Constructor.

odcore::io::protocol::NetstringsProtocol::~NetstringsProtocol ( )
virtual

References setStringListener().

Member Function Documentation

void odcore::io::protocol::NetstringsProtocol::nextString ( const string &  s)
virtual

This method is called whenever a new string occurs.

Parameters
sString that has been occured.

Implements odcore::io::StringListener.

void odcore::io::protocol::NetstringsProtocol::send ( const string &  data)

This method sends the data in the following format:

Size : Data ,

Size: data.length() as string

Parameters
dataData to be sent.

References odcore::io::protocol::AbstractProtocol::sendByStringSender().

void odcore::io::protocol::AbstractProtocol::sendByStringSender ( const string &  data)
inherited

This method needs to be called by subclasses to actually send some data according to the implemented protocol.

Parameters
dataData to be sent.

References odcore::io::StringSender::send().

Referenced by odcore::io::protocol::StringProtocol::send(), and send().

void odcore::io::protocol::NetstringsProtocol::setStringListener ( StringListener listener)
virtual

This method sets the StringListener that will receive incoming data.

Parameters
listenerStringListener that will receive incoming data.

Implements odcore::io::StringObserver.

Referenced by ~NetstringsProtocol().

void odcore::io::protocol::AbstractProtocol::setStringSender ( StringSender sender)
inherited

This method sets the StringSender (implemented by a connection like SerialPort) that can actually send the data.

Parameters
senderStringSender that will send the data.

Referenced by odcore::io::protocol::AbstractProtocol::~AbstractProtocol().