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.