MessageTranslator¶
-
class
kanzi::connect
::
MessageTranslator
¶ A class that translates raw binary data to network messages and vice versa.
Public Types
-
typedef function<MessagePackageSharedPtr()>
CreationFunction
¶ Creator function for network message types.
-
typedef vector<char>
MtDataBuffer
¶ Container type for raw data.
Public Functions
-
MessageTranslator
(MessagePackage::SerializationFormat format = MessagePackage::SerializationFormatBinary)¶ Constructor.
-
~MessageTranslator
()¶ Destructor.
-
MessagePackageSharedPtr
createMessage
(const string &type)¶ Creates message of given type.
- Return
New message instance of given type.
- Parameters
type
: Type of the message.
-
void
getRaw
(MtDataBuffer &data)¶ Translates outgoing message queue to raw data that can be serialized across network.
- Parameters
data
: Output raw data buffer.
-
void
receive
(int clientId, MessageArray &messages)¶ Translates received data in incoming data pool to messages.
- Parameters
clientId
: Id of the client that sent the messages.messages
: Container for incoming messages.
-
MessagePackage::SerializationFormat &
serializationFormat
()¶ Returns the serialization type of an attached network adapter.
- Return
Serialization format.
-
void
setRaw
(const MtDataBuffer &data)¶ Copies given data to incoming data pool that can be later on translated to network messages.
- Parameters
data
: Incoming raw data buffer.
-
bool
transmit
(const MessagePackage &message)¶ Pushes given message to outgoing message queue that will be processed later on.
Public Static Functions
Deserializes array of messages (see MessageContainer) from an array of bytes.
- Return
True on success.
- Parameters
serializer
: Message container into which extract messagesinBuffer
: Array containing serialized messages.format
: Serialization format. Either binary or JSON.hasLength
: Boolean indicating whether serialized buffer contains payload length.
Serializes array of messages (see MessageContainer) into array of bytes that has length of the payload encoded.
- Parameters
serializer
: Message container to be serializedoutBuffer
: Array, into which serialized bytes are appendedformat
: Serialization format. Either binary or JSON.
-
typedef function<MessagePackageSharedPtr()>