4#include "Internal/SerializationBinaryBuffer.h"
5#include "Internal/SerializationBinaryReadVersioned.h"
6#include "Internal/SerializationBinaryReadWriteExact.h"
8#include "SerializationBinaryOptions.h"
52 SerializationBinaryBufferWriter writer(buffer);
53 using Writer = Serialization::SerializerBinaryReadWriteExact<SerializationBinaryBufferWriter, T>;
54 if (not Writer::serialize(value, writer))
57 *numberOfWrites = writer.numberOfOperations;
98 SerializationBinaryBufferReader bufferReader(buffer);
99 using Reader = Serialization::SerializerBinaryReadWriteExact<SerializationBinaryBufferReader, T>;
100 if (not Reader::serialize(value, bufferReader))
103 *numberOfReads = bufferReader.numberOfOperations;
104 return bufferReader.positionIsAtEnd();
142 template <
typename T>
147 SerializationBinaryBufferReader readerBuffer(buffer);
148 using Reader = Serialization::SerializerBinaryReadVersioned<SerializationBinaryBufferReader, T>;
149 SerializationSchema versionSchema(schema);
150 versionSchema.options = options;
151 if (not Reader::readVersioned(value, readerBuffer, versionSchema))
154 *numberOfReads = readerBuffer.numberOfOperations;
155 return readerBuffer.positionIsAtEnd();
163 template <
typename T>
166 constexpr auto typeInfos = Reflection::Schema::template compile<T>().typeInfos;
167 constexpr uint32_t numInfos = typeInfos.size;
173 return write(value, buffer, numberOfWrites);
181 template <
typename T>
184 size_t* numberOfReads =
nullptr)
190 memcpy(&numInfos, numInfosSlice.
data(),
sizeof(numInfos));
199 constexpr auto sourceSchema = Reflection::Schema::template compile<T>().typeInfos;
204 if (sourceSchema.equals(serializedSchema))
207 return loadExact(value, serializedDataSlice);
212 return loadVersioned(value, serializedDataSlice, serializedSchema, options, numberOfReads);
unsigned int uint32_t
Platform independent (4) bytes unsigned int.
Definition: PrimitiveTypes.h:38
#define SC_TRY(expression)
Checks the value of the given expression and if failed, returns this value to caller.
Definition: Result.h:48
[reflectionSnippet3]
Definition: Reflection.h:64
Loads or writes binary data with its associated reflection schema from or into a C++ object.
Definition: SerializationBinary.h:24
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.
Definition: SerializationBinary.h:143
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.
Definition: SerializationBinary.h:164
static bool write(T &value, Vector< uint8_t > &buffer, size_t *numberOfWrites=nullptr)
Writes object T to a binary buffer.
Definition: SerializationBinary.h:50
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.
Definition: SerializationBinary.h:96
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::writeWith...
Definition: SerializationBinary.h:182
Conversion options for the binary versioned deserializer.
Definition: SerializationBinaryOptions.h:12
View over a contiguous sequence of items (pointer + size in elements).
Definition: Span.h:21
constexpr const Type * data() const
Returns pointer to first element of the span.
Definition: Span.h:89
constexpr bool sliceStart(SizeType offsetInElements, Span &destination) const
Creates another Span, starting at an offset in elements from current Span, until end.
Definition: Span.h:117
Span< T > reinterpret_as_array_of() const
Reinterprets the current span as an array of the specified type.
Definition: Span.h:74
constexpr bool sliceStartLength(SizeType offsetInElements, SizeType lengthInElements, Span &destination) const
Creates another Span, starting at an offset in elements from current Span of specified length.
Definition: Span.h:134
A contiguous sequence of heap allocated elements.
Definition: Vector.h:51
bool append(Span< const T > data)
Appends a range of items copying them at the end of vector.
Definition: Vector.h:520