class BinarySerializer

Encodes/decodes all the fields of the provided object into/from a binary format.

Fields are encoded using their unique IDs. Encoded data will remain compatible for decoding even if you modify the encoded class, as long as you assign new unique field IDs to added/modified fields.

Like for any serializable class, fields are defined in RTTIType that each IReflectable class must be able to return.

Any data the object or its children are pointing to will also be serialized (unless the pointer isn't registered in RTTIType). Upon decoding the pointer addresses will be set to proper values.

Public

Constructors

BinarySerializer

BinarySerializer()

Methods

Encode

void Encode(IReflectable *object, const SPtr<DataStream> &stream, RTTIOperationContext &context, BinarySerializerFlags flags = BinarySerializerFlag::None)

Encodes all serializable fields provided by into a binary format.

object
Object to encode into binary format.
stream
Stream into which to output the encoded data. The stream must own its memory buffer so it may grow as required during encoding, or your must guarantee the stream is of adequate size otherwise.
context
Optional object that will be passed along to all serialized objects through RTTI operation notify methods. Can be used for controlling serialization, maintaining state or sharing information between objects during serialization.
flags
Flags used for controlling serialization.

Encode

void Encode(IReflectable *object, const SPtr<DataStream> &stream, BinarySerializerFlags flags = BinarySerializerFlag::None)

Overload of Encode(IReflectable*, const SPtr <DataStream > & , BinarySerializerFlags, RTTIOperationContext & ) that uses default constructed context.

Decode

SPtr<IReflectable> Decode(const SPtr<DataStream> &stream, u32 dataLength, RTTIOperationContext &context, BinarySerializerFlags flags = BinarySerializerFlag::None, Function<void (float)> progress = nullptr, SPtr<RTTISchema> schema = nullptr)

Decodes an object from binary data.

stream
Stream containing the binary data to decode.
dataLength
Length of the data in bytes. If zero, all the data from the stream will be read.
context
Optional object that will be passed along to all serialized objects through their deserialization callbacks. Can be used for controlling deserialization, maintaining state or sharing information between objects during deserialization.
progress
Optional callback that will occasionally trigger, reporting the current progress of the operation. The reported value is in range [0, 1].
schema
RTTI schema that contains information about types as they were when the data was originally serialized. Schema is only used (and required) if BinarySerializerFlag::NoMeta is set, otherwise this information is read directly from the encoded data.

Decode

SPtr<IReflectable> Decode(const SPtr<DataStream> &stream, u32 dataLength, BinarySerializerFlags flags = BinarySerializerFlag::None, std::function<void (float)> progress = nullptr, SPtr<RTTISchema> schema = nullptr)

Overload of Decode(const SPtr <DataStream > & , u32, RTTIOperationContext, BinarySerializerFlags, Function <void (float)>, SPtr <RTTISchema >) that uses default constructed context.

Private

Fields

mTotalBytesToRead

u32 mTotalBytesToRead

mNextProgressReport

u32 mNextProgressReport

mAlloc

mBuffer

Bitstream mBuffer

mContext

mReportProgress

std::function<void (float)> mReportProgress