DelegateMQ
|
The serialize class binary serializes and deserializes C++ objects. More...
#include <msg_serialize.h>
Classes | |
class | I |
Abstract interface that all serialized user defined classes inherit. More... | |
Public Types | |
enum class | Type { UNKNOWN = 0 , LITERAL = 1 , STRING = 8 , WSTRING = 9 , VECTOR = 20 , MAP = 21 , LIST = 22 , SET = 23 , ENDIAN = 30 , USER_DEFINED = 31 } |
enum class | ParsingError { NONE , TYPE_MISMATCH , STREAM_ERROR , STRING_TOO_LONG , CONTAINER_TOO_MANY , INVALID_INPUT , END_OF_FILE } |
typedef void(*) | ErrorHandler(ParsingError error, int line, const char *file) |
typedef void(*) | ParseHandler(const std::type_info &typeId, size_t size) |
Public Member Functions | |
serialize ()=default | |
~serialize ()=default | |
bool | LE () |
std::istream & | readEndian (std::istream &is, bool &littleEndian) |
void | writeEndian (std::ostream &os) |
std::istream & | read (std::istream &is, I *t_) |
std::istream & | read (std::istream &is, std::string &s) |
std::istream & | read (std::istream &is, std::wstring &s) |
std::istream & | read (std::istream &is, char *str) |
std::istream & | read (std::istream &is, std::vector< bool > &container) |
std::ostream & | write (std::ostream &os, I *t_) |
std::ostream & | write (std::ostream &os, const std::string &s) |
std::ostream & | write (std::ostream &os, std::string &s) |
std::ostream & | write (std::ostream &os, const std::wstring &s) |
std::ostream & | write (std::ostream &os, std::wstring &s) |
std::ostream & | write (std::ostream &os, char *str) |
std::ostream & | write (std::ostream &os, const char *str) |
std::ostream & | write (std::ostream &os, std::vector< bool > &container) |
template<typename T > | |
std::istream & | read (std::istream &is, T &t_, bool readPrependedType=true) |
template<typename T > | |
std::ostream & | write (std::ostream &os, T &t_, bool prependType=true) |
template<class T > | |
std::ostream & | write (std::ostream &os, std::vector< T > &container) |
template<class T > | |
std::istream & | read (std::istream &is, std::vector< T > &container) |
template<class T > | |
std::ostream & | write (std::ostream &os, std::vector< T * > &container) |
template<class T > | |
std::istream & | read (std::istream &is, std::vector< T * > &container) |
template<class K , class V , class P > | |
std::ostream & | write (std::ostream &os, std::map< K, V, P > &container) |
template<class K , class V , class P > | |
std::istream & | read (std::istream &is, std::map< K, V, P > &container) |
template<class K , class V , class P > | |
std::ostream & | write (std::ostream &os, std::map< K, V *, P > &container) |
template<class K , class V , class P > | |
std::istream & | read (std::istream &is, std::map< K, V *, P > &container) |
template<class T , class P > | |
std::ostream & | write (std::ostream &os, std::set< T, P > &container) |
template<class T , class P > | |
std::istream & | read (std::istream &is, std::set< T, P > &container) |
template<class T , class P > | |
std::ostream & | write (std::ostream &os, std::set< T *, P > &container) |
template<class T , class P > | |
std::istream & | read (std::istream &is, std::set< T *, P > &container) |
template<class T > | |
std::ostream & | write (std::ostream &os, std::list< T > &container) |
template<class T > | |
std::istream & | read (std::istream &is, std::list< T > &container) |
template<class T > | |
std::ostream & | write (std::ostream &os, std::list< T * > &container) |
template<class T > | |
std::istream & | read (std::istream &is, std::list< T * > &container) |
void | setErrorHandler (ErrorHandler error_handler_) |
ParsingError | getLastError () const |
void | clearLastError () |
void | setParseHandler (ParseHandler parse_handler_) |
The serialize class binary serializes and deserializes C++ objects.
Each class need to implement the serialize::I abstract interface to allow binary serialization to any stream. A default constructor is required for the serialized object. Most container elements can be stored by value or by pointer. C++ containers supported are:
vector list map set string wstring char[]
Always check the input stream or output stream to ensure no errors before using data. e.g.
if (ss.good()) // Do something with input or output data
This serialization class is not thread safe and a serialie instance should only be accessed from a single task.
The serialize class support receiving objects that have more or less data fields that what is currenting being parsed. If more data is received after parsing an object, the extra data is discard. If less data is received, the parsing of the extra data fields does not occur. This supports the protocol changing by adding new data elements to an object. Once the protocol is released at a particular version, new data elements can be added but existing ones cannot be removed/changed.
void(*) serialize::ErrorHandler(ParsingError error, int line, const char *file) |
void(*) serialize::ParseHandler(const std::type_info &typeId, size_t size) |
|
strong |
|
strong |
|
default |
|
default |
|
inline |
|
inline |
|
inline |
Returns true if little endian.
|
inline |
Read a character string from a stream.
[in] | is | - the input stream |
[in] | str | - the character string to read into |
|
inline |
Read a user defined object implementing the serialize:I interface from a stream. Normally the send and reciever object is the same size. However, if a newer version of the object is introduced on one side the sizes will differ. If received object is smaller than sent object, the extra data in the sent object is discarded.
[in] | is | - the input stream |
[in] | t_ | - the object to read |
|
inline |
Read into a list container from a stream. Items in list stored by pointer. Operator new called to create object instances.
[in] | is | - the input stream |
[in] | container | - the list container to read into |
|
inline |
Read into a list container from a stream. Items in list are stored by value.
[in] | is | - the input stream |
[in] | container | - the list container to read into |
|
inline |
Read into a map container from a stream. Items in map stored by pointer. Operator new called to create object instances.
[in] | is | - the input stream |
[in] | container | - the map container to read into |
|
inline |
Read into a map container from a stream. Items in map are stored by value.
[in] | is | - the input stream |
[in] | container | - the map container to read into |
|
inline |
Read into a set container from a stream. Items in set stored by pointer. Operator new called to create object instances.
[in] | is | - the input stream |
[in] | container | - the set container to read into |
|
inline |
Read into a set container from a stream. Items in set are stored by value.
[in] | is | - the input stream |
[in] | container | - the set container to read into |
|
inline |
Read a str::string from a stream.
[in] | os | - the input stream |
[in] | s | - the string to read |
|
inline |
Read a vector<bool> container from a stream. The vector<bool> items are stored differently and therefore need special handling to serialize. Unlike other specializations of vector, std::vector<bool> does not manage a dynamic array of bool objects. Instead, it is supposed to pack the boolean values into a single bit each.
[in] | is | - the input stream |
[in] | container | - the vector container to read into |
|
inline |
Read into a vector container from a stream. Items in vector stored by pointer. Operator new called to create object instances.
[in] | is | - the input stream |
[in] | container | - the vector container to read into |
|
inline |
Read into a vector container from a stream. Items in vector are stored by value.
[in] | is | - the input stream |
[in] | container | - the vector container to read into |
|
inline |
Read a str::wstring from a stream.
[in] | os | - the input stream |
[in] | s | - the string to read |
|
inline |
Read an object from a stream.
[in] | is | - the input stream |
[in] | t_ | - the object to read into |
|
inline |
Read endian from stream.
[in] | istream | - input stream |
|
inline |
|
inline |
|
inline |
Write a character string to a stream.
[in] | os | - the output stream |
[in] | str | - the character string to write. |
|
inline |
Write a const character string to a stream.
[in] | os | - the output stream |
[in] | str | - the character string to write. |
|
inline |
Write a const std::string to a stream.
[in] | os | - the output stream |
[in] | s | - the string to write |
|
inline |
Write a const str::wstring to a stream.
[in] | os | - the output stream |
[in] | s | - the string to write |
|
inline |
Write a user defined object implementing the serialize:I interface to a stream.
[in] | os | - the output stream |
[in] | t_ | - the object to write |
|
inline |
Write a list container to a stream. The items in list are stored by pointer.
[in] | os | - the output stream |
[in] | container | - the list container to write |
|
inline |
Write a list container to a stream. The items in list are stored by value.
[in] | os | - the output stream |
[in] | container | - the list container to write |
|
inline |
Write a map container to a stream. The items in map are stored by pointer.
[in] | os | - the output stream |
[in] | container | - the map container to write |
|
inline |
Write a map container to a stream. The items in map are stored by value.
[in] | os | - the output stream |
[in] | container | - the map container to write |
|
inline |
Write a set container to a stream. The items in set are stored by pointer.
[in] | os | - the output stream |
[in] | container | - the set container to write |
|
inline |
Write a set container to a stream. The items in set are stored by value.
[in] | os | - the output stream |
[in] | container | - the set container to write |
|
inline |
Write a std::string to a stream.
[in] | os | - the output stream |
[in] | s | - the string to write |
|
inline |
Write a vector<bool> container to a stream. The vector<bool> items are stored differently and therefore need special handling to serialize. Unlike other specialisations of vector, std::vector<bool> does not manage a dynamic array of bool objects.Instead, it is supposed to pack the boolean values into a single bit each.
[in] | os | - the output stream |
[in] | container | - the vector container to write |
|
inline |
Write a vector container to a stream. The items in vector are stored by pointer.
[in] | os | - the output stream |
[in] | container | - the vector container to write |
|
inline |
Write a vector container to a stream. The items in vector are stored by value.
[in] | os | - the output stream |
[in] | container | - the vector container to write |
|
inline |
Write a str::wstring to a stream.
[in] | os | - the output stream |
[in] | s | - the string to write |
|
inline |
Write an object to a stream.
[in] | os | - the output stream |
[in] | t_ | - the object to write |
|
inline |
Write current CPU endian to stream.
[in] | ostream | - output stream |