Inspirel banner

Programming Distributed Systems with YAMI4

3.13.2 C++

In order to describe a raw binary data the program has to use the raw_buffer_data_source wrapper. This wrapper was prepared to handle scattered (non-contiguous) binary buffers.

The following example shows how to describe two binary buffers as a pair of arrays - one pointing to the beginning of each buffer and the other one holding their sizes:

vector<char> buf1;
vector<char> buf2;
// ...

const char * buffers[2];
buffers[0] = &buf1[0];
buffers[1] = &buf2[0];

std::size_t sizes[2];
sizes[0] = buf1.size();
sizes[1] = buf2.size();

Once the list of buffers is prepared, it can be wrapped as a serializable object:

raw_binary_data_source raw_binary(buffers, sizes, 2);

The raw_binary object above can be passed to YAMI4 instead of regular parameters object. This is possible because both parameters and raw_buffer_data_source implement the serializable interface and objects of both types can be used for describing data.

Users with special data structure requirements can also provide their own implementations of the serializable interface and use them with message sending operations.