Kanzi Connect  1.1.10
Kanzi Connect C++ API
kanzi::connect::MessageTranslator Class Reference

A class that translates raw binary data to network messages and vice versa. More...

#include <message_translator.hpp>

Public Types

typedef function< MessagePackageSharedPtr()> CreationFunction
 Creator function for network message types. More...
 
typedef vector< char > MtDataBuffer
 Container type for raw data. More...
 

Public Member Functions

MessagePackageSharedPtr createMessage (const string &type)
 Creates message of given type. More...
 
void getRaw (MtDataBuffer &data)
 Translates outgoing message queue to raw data that can be serialized across network. More...
 
 MessageTranslator (MessagePackage::SerializationFormat format=MessagePackage::SerializationFormatBinary)
 Constructor. More...
 
void receive (int clientId, MessageArray &messages)
 Translates received data in incoming data pool to messages. More...
 
MessagePackage::SerializationFormatserializationFormat ()
 Returns the serialization type of an attached network adapter. More...
 
void setRaw (const MtDataBuffer &data)
 Copies given data to incoming data pool that can be later on translated to network messages. More...
 
bool transmit (const MessagePackage &message)
 Pushes given message to outgoing message queue that will be processed later on. More...
 
 ~MessageTranslator ()
 Destructor. More...
 

Static Public Member Functions

static bool unwrap (shared_ptr< MessageContainer > serializer, const vector< char > &inBuffer, MessagePackage::SerializationFormat format, bool hasLength)
 Deserializes array of messages (see MessageContainer) from an array of bytes. More...
 
static void wrap (const shared_ptr< MessageContainer > serializer, vector< char > &outBuffer, MessagePackage::SerializationFormat format)
 Serializes array of messages (see MessageContainer) into array of bytes that has length of the payload encoded. More...
 

Detailed Description

A class that translates raw binary data to network messages and vice versa.

Member Typedef Documentation

◆ CreationFunction

Creator function for network message types.

◆ MtDataBuffer

Container type for raw data.

Constructor & Destructor Documentation

◆ MessageTranslator()

kanzi::connect::MessageTranslator::MessageTranslator ( MessagePackage::SerializationFormat  format = MessagePackage::SerializationFormatBinary)

Constructor.

◆ ~MessageTranslator()

kanzi::connect::MessageTranslator::~MessageTranslator ( )

Destructor.

Member Function Documentation

◆ createMessage()

MessagePackageSharedPtr kanzi::connect::MessageTranslator::createMessage ( const string &  type)

Creates message of given type.

Parameters
typeType of the message.
Returns
New message instance of given type.

◆ getRaw()

void kanzi::connect::MessageTranslator::getRaw ( MtDataBuffer data)

Translates outgoing message queue to raw data that can be serialized across network.

Parameters
dataOutput raw data buffer.

◆ receive()

void kanzi::connect::MessageTranslator::receive ( int  clientId,
MessageArray messages 
)

Translates received data in incoming data pool to messages.

Parameters
clientIdId of the client that sent the messages.
messagesContainer for incoming messages.

◆ serializationFormat()

MessagePackage::SerializationFormat& kanzi::connect::MessageTranslator::serializationFormat ( )
inline

Returns the serialization type of an attached network adapter.

Returns
Serialization format.

◆ setRaw()

void kanzi::connect::MessageTranslator::setRaw ( const MtDataBuffer data)

Copies given data to incoming data pool that can be later on translated to network messages.

Parameters
dataIncoming raw data buffer.

◆ transmit()

bool kanzi::connect::MessageTranslator::transmit ( const MessagePackage message)

Pushes given message to outgoing message queue that will be processed later on.

◆ unwrap()

static bool kanzi::connect::MessageTranslator::unwrap ( shared_ptr< MessageContainer serializer,
const vector< char > &  inBuffer,
MessagePackage::SerializationFormat  format,
bool  hasLength 
)
static

Deserializes array of messages (see MessageContainer) from an array of bytes.

Parameters
serializerMessage container into which extract messages
inBufferArray containing serialized messages.
formatSerialization format. Either binary or JSON.
hasLengthBoolean indicating whether serialized buffer contains payload length.
Returns
True on success.

◆ wrap()

static void kanzi::connect::MessageTranslator::wrap ( const shared_ptr< MessageContainer serializer,
vector< char > &  outBuffer,
MessagePackage::SerializationFormat  format 
)
static

Serializes array of messages (see MessageContainer) into array of bytes that has length of the payload encoded.

Parameters
serializerMessage container to be serialized
outBufferArray, into which serialized bytes are appended
formatSerialization format. Either binary or JSON.

The documentation for this class was generated from the following file: