BinarySerializerObject Class Reference

CPP API: mio::BinarySerializerObject Class Reference
mio::BinarySerializerObject Class Reference

Stores a binary serialized object. More...

#include <binary_serializer.h>

Inheritance diagram for mio::BinarySerializerObject:
Collaboration diagram for mio::BinarySerializerObject:

Public Member Functions

void add_element (const std::string &name, const std::string &value)
 Add string element to this object. More...
 
template<class T >
requires std::is_trivial_v< T > void add_element (const std::string &name, const T &value)
 Add element of basic type to this object. More...
 
template<class Iter >
void add_list (const std::string &name, Iter b, Iter e)
 Add a list of elements to this object. More...
 
template<class T >
void add_optional (const std::string &name, const T *value)
 Add optional element to this object. More...
 
 BinarySerializerObject (ByteStream &stream, std::shared_ptr< IOStatus > status, int flags)
 
template<class T >
requires(!std::is_trivial_v< T >) IOResult< T > expect_element(const std IOResult< std::string > expect_element (const std::string &name, Tag< std::string > tag)
 Get deserializable element from this object. More...
 
template<class T >
requires(!std::is_trivial_v< T >) void add_element(const std requires std::is_trivial_v< T > IOResult< T > expect_element (const std::string &name, Tag< T > tag)
 Add serializable value as an element to this object. More...
 
template<class T >
requires std::is_trivial_v< T > IOResult< T > expect_element (const std::string &name, Tag< T >)
 
template<class T >
IOResult< std::vector< T > > expect_list (const std::string &name, Tag< T >)
 Get a list of elements from this object. More...
 
template<class T >
IOResult< boost::optional< T > > expect_optional (const std::string &name, Tag< T >)
 Get optional element from this object. More...
 
- Public Member Functions inherited from mio::SerializerBase
int flags () const
 Flags that determine the behavior of serialization. More...
 
 SerializerBase (std::shared_ptr< IOStatus > status, int flags)
 Constructor that sets status and flags. More...
 
void set_error (const IOStatus &status)
 Set the current status of serialization. More...
 
void set_flags (int f)
 Set flags that determine the behavior of serialization. More...
 
const IOStatusstatus () const
 The current status of serialization. More...
 

Private Attributes

ByteStreamm_stream
 Reference to a stream that stores the serialized bytes. More...
 

Additional Inherited Members

- Protected Attributes inherited from mio::SerializerBase
int m_flags
 
std::shared_ptr< IOStatusm_status
 

Detailed Description

Stores a binary serialized object.

See io.h for documentation of serialization.

Constructor & Destructor Documentation

◆ BinarySerializerObject()

mio::BinarySerializerObject::BinarySerializerObject ( ByteStream stream,
std::shared_ptr< IOStatus status,
int  flags 
)
inline

Member Function Documentation

◆ add_element() [1/2]

void mio::BinarySerializerObject::add_element ( const std::string &  name,
const std::string &  value 
)
inline

Add string element to this object.

Parameters
nameName of the element.
valueValue to be serialized.

◆ add_element() [2/2]

template<class T >
requires std::is_trivial_v< T > void mio::BinarySerializerObject::add_element ( const std::string &  name,
const T &  value 
)

Add element of basic type to this object.

As an optimization, also handles trivial structs, Enums, etc (everything that can be memcpy'd.)

Parameters
nameName of the element.
valueValue to be serialized.

◆ add_list()

template<class Iter >
void mio::BinarySerializerObject::add_list ( const std::string &  name,
Iter  b,
Iter  e 
)

Add a list of elements to this object.

Parameters
nameName of the list.
bIterator to beginning of the list.
eIterator to end of the list.

◆ add_optional()

template<class T >
void mio::BinarySerializerObject::add_optional ( const std::string &  name,
const T *  value 
)

Add optional element to this object.

Parameters
nameName of the element.
valueValue to be serialized. Nullptr if empty.

◆ expect_element() [1/3]

template<class T >
requires (!std::is_trivial_v<T>) IOResult<T> expect_element( const std IOResult<std::string> mio::BinarySerializerObject::expect_element ( const std::string &  name,
Tag< std::string >  tag 
)

Get deserializable element from this object.

Parameters
nameName of the element.
tagTag that determines the type of the element.
Returns
Deserialized value. Get serialized string element from this object.
Parameters
nameName of the element.
tagTag that determines the type of the element.
Returns
Deserialized value.

◆ expect_element() [2/3]

template<class T >
requires (!std::is_trivial_v<T>) void add_element( const std requires std::is_trivial_v<T> IOResult<T> mio::BinarySerializerObject::expect_element ( const std::string &  name,
Tag< T >  tag 
)

Add serializable value as an element to this object.

Parameters
nameName of the element.
valueValue to be serialized. Get element of basic type from this object. As an optimization, also handles trivial structs, Enums, etc (everything that can be memcpy'd.)
nameName of the element.
tagTag that determines the type of the element.
Returns
Deserialized value.

◆ expect_element() [3/3]

template<class T >
requires std::is_trivial_v<T> IOResult<T> mio::BinarySerializerObject::expect_element ( const std::string &  name,
Tag< T >   
)

◆ expect_list()

template<class T >
IOResult< std::vector< T > > mio::BinarySerializerObject::expect_list ( const std::string &  name,
Tag< T >   
)

Get a list of elements from this object.

Parameters
nameName of the list.
Returns
List of deserialized elements.

◆ expect_optional()

template<class T >
IOResult< boost::optional< T > > mio::BinarySerializerObject::expect_optional ( const std::string &  name,
Tag< T >   
)

Get optional element from this object.

Parameters
nameName of the element.
Returns
Deserialized optional value.

Member Data Documentation

◆ m_stream

ByteStream& mio::BinarySerializerObject::m_stream
private

Reference to a stream that stores the serialized bytes.