Sierra Toolkit
Version of the Day
|
Struct Marshal
is a data packer for sending and receiving parallel messages. The data put-to (<<) is appended to the stream as a string of bytes, likewise data gotten-from (>>) is extracted from the stream into the object as a string of bytes.
More...
#include <Marshal.hpp>
Public Member Functions | |
Marshal (unsigned type_check=TYPE_CHECK_NONE) | |
Marshal (const std::string &s) | |
std::string | str () const |
Member function str returns the string of packed bytes created by put-to operations to the stream. More... | |
size_t | size () const |
Member function size returns the byte count of the string of packed bytes creates by put-to operations to the stream. More... | |
void | write (const char *address, size_t byte_count) |
Member function write writer bytes to the packed byte stream. More... | |
void | read (char *address, size_t byte_count) |
Member function read reads bytes from the packed byte stream. More... | |
operator void * () const | |
Member function operator void * returns the state of the packed byte stream. More... | |
Public Attributes | |
std::stringstream | stream |
Packed byte stream to put-to or get-from. | |
unsigned | m_typeCheck |
Type checking to activate. | |
Struct Marshal
is a data packer for sending and receiving parallel messages. The data put-to (<<) is appended to the stream as a string of bytes, likewise data gotten-from (>>) is extracted from the stream into the object as a string of bytes.
The write() and read() functions perform the data movements to and from the packed stream.
The common implementation is the create a << and >> operator for an object which properly appends and extracts the object's members.
The object can put-to and get-from it's typeid() to add type checking. This operation ensures that the data types being read was the data type written before the data is extracted. This type checking can be disabled since it may be desired to put-to an object of one type, but get-from into an object of an extractable but different type.
The TYPE_CHECK bit masks can be provided at put-to Marshal construction to activate the type checking. The Marshaller send the type check code as the first message to allow the get-from to initialize properly.
The put-to operator and get-from operators for plain old data, std::string, std::vector and std::list have been implemented. Additional ones could be added here, or left to the developer using the marshaller.
The stream and type_check members were left as public due to the extensive use. If this proves bothersome, getter/setter methods could be introduced.
Definition at line 49 of file Marshal.hpp.
stk_classic::Marshal::Marshal | ( | unsigned | type_check = TYPE_CHECK_NONE | ) |
Creates a new Marshal
instance for put-to operations.
Definition at line 153 of file Marshal.cpp.
|
explicit |
Creates a new Marshal
instance for get-from operations.
s | a std::string constant variable of packed bytes to extract using the get-from operators. |
Definition at line 163 of file Marshal.cpp.
std::string stk_classic::Marshal::str | ( | ) | const |
Member function str
returns the string of packed bytes created by put-to operations to the stream.
std::string
created from the packed byte stream. Definition at line 173 of file Marshal.cpp.
size_t stk_classic::Marshal::size | ( | ) | const |
Member function size
returns the byte count of the string of packed bytes creates by put-to operations to the stream.
size_t
in bytes of the packed byte stream. Definition at line 180 of file Marshal.cpp.
void stk_classic::Marshal::write | ( | const char * | address, |
size_t | byte_count | ||
) |
Member function write
writer bytes to the packed byte stream.
byte_count | a size_t value of the number of packed bytes to write. |
address | a char constant pointer to get the bytes from. |
Definition at line 193 of file Marshal.cpp.
void stk_classic::Marshal::read | ( | char * | address, |
size_t | byte_count | ||
) |
Member function read
reads bytes from the packed byte stream.
byte_count | a size_t value of the number of packed bytes to read. |
address | a char constant pointer to put the bytes to. |
Definition at line 202 of file Marshal.cpp.
stk_classic::Marshal::operator void * | ( | ) | const |
Member function operator void *
returns the state of the packed byte stream.
void
const pointer which is non-zero if status is good. Definition at line 186 of file Marshal.cpp.