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.
- Parameters
type – Type of the message.
- Returns
New message instance of given type.
-
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.
-
inline MessagePackage::SerializationFormat &
serializationFormat()¶ Returns the serialization type of an attached network adapter.
- Returns
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.
- Parameters
serializer – Message container into which extract messages
inBuffer – Array containing serialized messages.
format – Serialization format. Either binary or JSON.
hasLength – Boolean indicating whether serialized buffer contains payload length.
- Returns
True on success.
Serializes array of messages (see MessageContainer) into array of bytes that has length of the payload encoded.
- Parameters
serializer – Message container to be serialized
outBuffer – Array, into which serialized bytes are appended
format – Serialization format. Either binary or JSON.
-
typedef function<MessagePackageSharedPtr()>