![]() |
FlatBuffers
An open source project by FPL.
|
Helper class to hold data needed in creation of a FlatBuffer. More...
#include <flatbuffers.h>
Helper class to hold data needed in creation of a FlatBuffer.
To serialize data, you typically call one of the Create*()
functions in the generated code, which in turn call a sequence of StartTable
/ PushElement
/AddElement
/EndTable
, or the builtin CreateString
/ CreateVector
functions. Do this is depth-first order to build up a tree to the root. Finish()
wraps up the buffer ready for transport.
Public Member Functions | |
void | Clear () |
Reset all the state in this FlatBufferBuilder so it can be reused to construct another buffer. More... | |
Offset< String > | CreateSharedString (const char *str, size_t len) |
Store a string in the buffer, which can contain any binary data. More... | |
Offset< String > | CreateSharedString (const char *str) |
Store a string in the buffer, which null-terminated. More... | |
Offset< String > | CreateSharedString (const std::string &str) |
Store a string in the buffer, which can contain any binary data. More... | |
Offset< String > | CreateSharedString (const String *str) |
Store a string in the buffer, which can contain any binary data. More... | |
Offset< String > | CreateString (const char *str, size_t len) |
Store a string in the buffer, which can contain any binary data. More... | |
Offset< String > | CreateString (const char *str) |
Store a string in the buffer, which is null-terminated. More... | |
Offset< String > | CreateString (const std::string &str) |
Store a string in the buffer, which can contain any binary data. More... | |
Offset< String > | CreateString (const String *str) |
Store a string in the buffer, which can contain any binary data. More... | |
uoffset_t | CreateUninitializedVector (size_t len, size_t elemsize, uint8_t **buf) |
Specialized version of CreateVector for non-copying use cases. More... | |
template<typename T > | |
Offset< Vector< T > > | CreateUninitializedVector (size_t len, T **buf) |
Specialized version of CreateVector for non-copying use cases. More... | |
template<typename T > | |
Offset< Vector< T > > | CreateVector (const T *v, size_t len) |
Serialize an array into a FlatBuffer vector . More... | |
template<typename T > | |
Offset< Vector< T > > | CreateVector (const std::vector< T > &v) |
Serialize a std::vector into a FlatBuffer vector . More... | |
template<typename T > | |
Offset< Vector< Offset< T > > > | CreateVectorOfSortedTables (Offset< T > *v, size_t len) |
Serialize an array of table offsets as a vector in the buffer in sorted order. More... | |
template<typename T > | |
Offset< Vector< Offset< T > > > | CreateVectorOfSortedTables (std::vector< Offset< T >> *v) |
Serialize an array of table offsets as a vector in the buffer in sorted order. More... | |
template<typename T > | |
Offset< Vector< const T * > > | CreateVectorOfStructs (const T *v, size_t len) |
Serialize an array of structs into a FlatBuffer vector . More... | |
template<typename T > | |
Offset< Vector< const T * > > | CreateVectorOfStructs (const std::vector< T > &v) |
Serialize a std::vector of structs into a FlatBuffer vector . More... | |
template<typename T > | |
void | Finish (Offset< T > root, const char *file_identifier=nullptr) |
Finish serializing a buffer by writing the root offset. More... | |
FlatBufferBuilder (uoffset_t initial_size=1024, const simple_allocator *allocator=nullptr) | |
Default constructor for FlatBufferBuilder. More... | |
void | ForceDefaults (bool fd) |
In order to save space, fields that are set to their default value don't get serialized into the buffer. More... | |
uint8_t * | GetBufferPointer () const |
Get the serialized buffer (after you call Finish() ). More... | |
uint8_t * | GetCurrentBufferPointer () const |
Get a pointer to an unfinished buffer. More... | |
uoffset_t | GetSize () const |
The current size of the serialized buffer, counting from the end. More... | |
unique_ptr_t | ReleaseBufferPointer () |
Get the released pointer to the serialized buffer. More... | |
Static Public Attributes | |
static const size_t | kFileIdentifierLength = 4 |
The length of a FlatBuffer file header. | |
|
inlineexplicit |
Default constructor for FlatBufferBuilder.
[in] | initial_size | The initial size of the buffer, in bytes. Defaults to1024 . |
[in] | allocator | A pointer to the simple_allocator that should be used. Defaults to nullptr , which means the default_allocator will be be used. |
|
inline |
Reset all the state in this FlatBufferBuilder so it can be reused to construct another buffer.
|
inline |
Store a string in the buffer, which can contain any binary data.
If a string with this exact contents has already been serialized before, instead simply returns the offset of the existing string.
[in] | str | A const char pointer to the data to be stored as a string. |
[in] | len | The number of bytes that should be stored from str . |
|
inline |
Store a string in the buffer, which null-terminated.
If a string with this exact contents has already been serialized before, instead simply returns the offset of the existing string.
[in] | str | A const char pointer to a C-string to add to the buffer. |
|
inline |
Store a string in the buffer, which can contain any binary data.
If a string with this exact contents has already been serialized before, instead simply returns the offset of the existing string.
[in] | str | A const reference to a std::string to store in the buffer. |
|
inline |
Store a string in the buffer, which can contain any binary data.
If a string with this exact contents has already been serialized before, instead simply returns the offset of the existing string.
[in] | str | A const pointer to a String struct to add to the buffer. |
|
inline |
Store a string in the buffer, which can contain any binary data.
[in] | str | A const char pointer to the data to be stored as a string. |
[in] | len | The number of bytes that should be stored from str . |
|
inline |
Store a string in the buffer, which is null-terminated.
[in] | str | A const char pointer to a C-string to add to the buffer. |
|
inline |
Store a string in the buffer, which can contain any binary data.
[in] | str | A const reference to a std::string to store in the buffer. |
|
inline |
Store a string in the buffer, which can contain any binary data.
[in] | str | A const pointer to a String struct to add to the buffer. |
|
inline |
Specialized version of CreateVector
for non-copying use cases.
Write the data any time later to the returned buffer pointer buf
.
[in] | len | The number of elements to store in the vector . |
[in] | elemsize | The size of each element in the vector . |
[out] | buf | A pointer to a uint8_t pointer that can be written to at a later time to serialize the data into a vector in the buffer. |
|
inline |
Specialized version of CreateVector
for non-copying use cases.
Write the data any time later to the returned buffer pointer buf
.
T | The data type of the data that will be stored in the buffer as a vector . |
[in] | len | The number of elements to store in the vector . |
[out] | buf | A pointer to a pointer of type T that can be written to at a later time to serialize the data into a vector in the buffer. |
|
inline |
Serialize an array into a FlatBuffer vector
.
T | The data type of the array elements. |
[in] | v | A pointer to the array of type T to serialize into the buffer as a vector . |
[in] | len | The number of elements to serialize. |
Offset
into the serialized data indicating where the vector is stored.
|
inline |
Serialize a std::vector
into a FlatBuffer vector
.
T | The data type of the std::vector elements. |
v | A const reference to the std::vector to serialize into the buffer as a vector . |
Offset
into the serialized data indicating where the vector is stored.
|
inline |
Serialize an array of table
offsets as a vector
in the buffer in sorted order.
T | The data type that the offset refers to. |
[in] | v | An array of type Offset<T> that contains the table offsets to store in the buffer in sorted order. |
[in] | len | The number of elements to store in the vector . |
Offset
into the serialized data indicating where the vector is stored.
|
inline |
Serialize an array of table
offsets as a vector
in the buffer in sorted order.
T | The data type that the offset refers to. |
[in] | v | An array of type Offset<T> that contains the table offsets to store in the buffer in sorted order. |
Offset
into the serialized data indicating where the vector is stored.
|
inline |
Serialize an array of structs into a FlatBuffer vector
.
T | The data type of the struct array elements. |
[in] | v | A pointer to the array of type T to serialize into the buffer as a vector . |
[in] | len | The number of elements to serialize. |
Offset
into the serialized data indicating where the vector is stored.
|
inline |
Serialize a std::vector
of structs into a FlatBuffer vector
.
T | The data type of the std::vector struct elements. |
[in] | v A const reference to the std::vector of structs to serialize into the buffer as a vector . |
Offset
into the serialized data indicating where the vector is stored.
|
inline |
Finish serializing a buffer by writing the root offset.
[in] | file_identifier | If a file_identifier is given, the buffer will be prefixed with a standard FlatBuffers file header. |
|
inline |
In order to save space, fields that are set to their default value don't get serialized into the buffer.
[in] | bool | fd When set to true , always serializes default values. |
|
inline |
Get the serialized buffer (after you call Finish()
).
uint8_t
pointer to the FlatBuffer data inside the buffer.
|
inline |
Get a pointer to an unfinished buffer.
uint8_t
pointer to the unfinished buffer.
|
inline |
The current size of the serialized buffer, counting from the end.
uoffset_t
with the current size of the buffer.
|
inline |
Get the released pointer to the serialized buffer.
unique_ptr
returned has a special allocator that knows how to deallocate this pointer (since it points to the middle of an allocation). Thus, do not mix this pointer with other unique_ptr
's, or call release()
/reset()
on it.