Loads or writes binary data with its associated reflection schema from or into a C++ object. More...
#include <SerializationBinary.h>
Static Public Member Functions | |
template<typename T > | |
static bool | write (T &value, Vector< uint8_t > &buffer, size_t *numberOfWrites=nullptr) |
Writes object T to a binary buffer. More... | |
template<typename T > | |
static bool | loadExact (T &value, Span< const uint8_t > buffer, size_t *numberOfReads=nullptr) |
Loads object T from binary buffer as written by SerializationBinary::write. More... | |
template<typename T > | |
static bool | loadVersioned (T &value, Span< const uint8_t > buffer, Span< const Reflection::TypeInfo > schema, SerializationBinaryOptions options={}, size_t *numberOfReads=nullptr) |
Deserialize object T from a Binary buffer with a reflection schema not matching T schema. More... | |
template<typename T > | |
static bool | writeWithSchema (T &value, Vector< uint8_t > &buffer, size_t *numberOfWrites=nullptr) |
Writes the reflection schema of object T followed by contents of object T to a binary buffer. More... | |
template<typename T > | |
static bool | loadVersionedWithSchema (T &value, Span< const uint8_t > buffer, SerializationBinaryOptions options={}, size_t *numberOfReads=nullptr) |
Loads object T using the schema information that has been prepended by SerializationBinary::writeWithSchema. More... | |
Loads or writes binary data with its associated reflection schema from or into a C++ object.
|
inlinestatic |
Loads object T
from binary buffer as written by SerializationBinary::write.
SC::SerializationBinary::loadExact can deserialize binary data into a struct whose schema has not changed from when SerializationBinary::write has been used to generate that same binary data. In other words if the schema of the type passed to SerializationBinary::write must match the one of current type being deserialized. If the two schemas hash match then it's possible to use this fast path, that skips all versioning checks.
T | Type of object to be deserialized (must be described by Reflection) |
value | The object to be deserialized |
buffer | The buffer holding actual bytes for deserialization |
numberOfReads | If provided, will return the number deserialization operations |
true
if deserialization succeededAssuming the following structs:
TopLevelStruct
can be serialized and de-serialized with the following code:
|
inlinestatic |
Deserialize object T
from a Binary buffer with a reflection schema not matching T
schema.
The versioned read serializer SC::SerializationBinary::loadVersioned must be used when source and destination schemas do not match. Compatibility flags can be customized through SC::SerializationBinaryOptions object, allowing to remap data coming from an older (or just different) version of the schema to the current one. SerializationBinary::loadVersioned will try to match the memberTag
field specified in [Reflection](Reflection) to match fields between source and destination schemas. When the types of the fields are different, a few options allow controlling the behaviour.
T | Type of object to be deserialized (must be described by Reflection) |
value | The object to deserialize |
buffer | The buffer holding the bytes to be used for deserialization |
schema | The schema used to serialize data in the buffer |
numberOfReads | If provided, will return the number deserialization operations |
options | Options for data conversion (allow dropping fields, array items etc) |
true
if deserialization succeeded
Assuming the following structs:
VersionedStruct2
can be deserialized from VersionedStruct1
in the following way
|
inlinestatic |
Loads object T
using the schema information that has been prepended by SerializationBinary::writeWithSchema.
The schema allows a "best effort" de-serialization trying to match fields with corresponding memberTag
.
|
inlinestatic |
Writes object T
to a binary buffer.
SC::SerializationBinary::write is used to serialize data. The schema itself is not used at all but it could written along with the binary data so that when reading back the data in a later version of the program, the correct choice can be made between deserializing using SerializationBinary::loadVersioned (slower but allows for missing fields and conversion) or deserializing using SerializationBinary::loadExact (faster, but schema must match 1:1).
T | Type of object to be serialized (must be described by Reflection) |
value | The object to be serialized |
buffer | The buffer that will receive serialized bytes |
numberOfWrites | If provided, will return the number of serialization operations |
true
if serialization succeededAssuming the following struct:
PrimitiveStruct
can be written to a binary buffer with the following code:
|
inlinestatic |
Writes the reflection schema of object T
followed by contents of object T
to a binary buffer.
The serialized buffer can be used with SerializationBinary::loadVersionedWithSchema to allow a "best effort" de-serialization trying to match fields with corresponding memberTag
.