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.
More...
#include <flatbuffers.h>
Classes | |
struct | FieldLoc |
struct | StringOffsetCompare |
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. If a string with this exact contents has already been serialized before, instead simply returns the offset of the existing string. More... | |
Offset< String > | CreateSharedString (const char *str) |
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. More... | |
Offset< String > | CreateSharedString (const std::string &str) |
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. More... | |
Offset< String > | CreateSharedString (const String *str) |
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. 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 (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... | |
template<typename T > | |
Offset< String > | CreateString (const T &str) |
Store a string in the buffer, which can contain any binary data. More... | |
template<typename T > | |
Offset< const T * > | CreateStruct (const T &structobj) |
Write a struct by itself, typically to be part of a union. More... | |
uoffset_t | CreateUninitializedVector (size_t len, size_t elemsize, uint8_t **buf) |
Specialized version of CreateVector for non-copying use cases. Write the data any time later to the returned buffer pointer buf . More... | |
template<typename T > | |
Offset< Vector< T > > | CreateUninitializedVector (size_t len, T **buf) |
Specialized version of CreateVector for non-copying use cases. Write the data any time later to the returned buffer pointer buf . 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< Offset< T > > > | CreateVector (const Offset< T > *v, size_t len) |
template<typename T > | |
Offset< Vector< T > > | CreateVector (const std::vector< T > &v) |
Serialize a std::vector into a FlatBuffer vector . More... | |
Offset< Vector< uint8_t > > | CreateVector (const std::vector< bool > &v) |
template<typename T > | |
Offset< Vector< T > > | CreateVector (size_t vector_size, const std::function< T(size_t i)> &f) |
Serialize values returned by a function into a FlatBuffer vector . This is a convenience function that takes care of iteration for you. More... | |
template<typename T , typename F , typename S > | |
Offset< Vector< T > > | CreateVector (size_t vector_size, F f, S *state) |
Serialize values returned by a function into a FlatBuffer vector . This is a convenience function that takes care of iteration for you. More... | |
template<typename T , typename S > | |
Offset< Vector< const T * > > | CreateVectorOfNativeStructs (const S *v, size_t len) |
Serialize an array of native structs into a FlatBuffer vector . More... | |
template<typename T , typename S > | |
Offset< Vector< const T * > > | CreateVectorOfNativeStructs (const std::vector< S > &v) |
Serialize a std::vector of native structs into a FlatBuffer vector . More... | |
template<typename T , typename S > | |
Offset< Vector< const T * > > | CreateVectorOfSortedNativeStructs (std::vector< S > *v) |
Serialize a std::vector of native structs into a FlatBuffer vector in sorted order. More... | |
template<typename T , typename S > | |
Offset< Vector< const T * > > | CreateVectorOfSortedNativeStructs (S *v, size_t len) |
Serialize an array of native structs into a FlatBuffer vector in sorted order. More... | |
template<typename T > | |
Offset< Vector< const T * > > | CreateVectorOfSortedStructs (std::vector< T > *v) |
Serialize a std::vector of structs into a FlatBuffer vector in sorted order. More... | |
template<typename T > | |
Offset< Vector< const T * > > | CreateVectorOfSortedStructs (T *v, size_t len) |
Serialize an array of structs into a FlatBuffer vector in sorted order. 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... | |
Offset< Vector< Offset< String > > > | CreateVectorOfStrings (const std::vector< std::string > &v) |
Serialize a std::vector<std::string> into a FlatBuffer vector . This is a convenience function for a common case. 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 (size_t vector_size, const std::function< void(size_t i, T *)> &filler) |
Serialize an array of structs into a FlatBuffer vector . More... | |
template<typename T , typename F , typename S > | |
Offset< Vector< const T * > > | CreateVectorOfStructs (size_t vector_size, F f, S *state) |
Serialize an array of structs into a FlatBuffer vector . More... | |
template<typename T , typename Alloc > | |
Offset< Vector< const T * > > | CreateVectorOfStructs (const std::vector< T, Alloc > &v) |
Serialize a std::vector of structs into a FlatBuffer vector . More... | |
void | DedupVtables (bool dedup) |
By default vtables are deduped in order to save space. More... | |
template<typename T > | |
void | Finish (Offset< T > root, const char *file_identifier=nullptr) |
Finish serializing a buffer by writing the root offset. More... | |
template<typename T > | |
void | FinishSizePrefixed (Offset< T > root, const char *file_identifier=nullptr) |
Finish a buffer with a 32 bit size field pre-fixed (size of the buffer following the size field). These buffers are NOT compatible with standard buffers created by Finish, i.e. you can't call GetRoot on them, you have to use GetSizePrefixedRoot instead. All >32 bit quantities in this buffer will be aligned when the whole size pre-fixed buffer is aligned. These kinds of buffers are useful for creating a stream of FlatBuffers. More... | |
FlatBufferBuilder (size_t initial_size=1024, Allocator *allocator=nullptr, bool own_allocator=false, size_t buffer_minalign=AlignOf< largest_scalar_t >()) | |
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... | |
size_t | GetBufferMinAlignment () |
get the minimum alignment this buffer needs to be accessed properly. This is only known once all elements have been written (after you call Finish()). You can use this information if you need to embed a FlatBuffer in some other buffer, such that you can later read it without first having to copy it into its own 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... | |
DetachedBuffer | Release () |
Get the released DetachedBuffer. More... | |
DetachedBuffer | ReleaseBufferPointer () |
Get the released pointer to the serialized buffer. More... | |
void | Reset () |
~FlatBufferBuilder () | |
Static Public Attributes | |
static const size_t | kFileIdentifierLength = 4 |
The length of a FlatBuffer file header. More... | |
Protected Types | |
typedef std::set< Offset< String >, StringOffsetCompare > | StringOffsetMap |
Protected Member Functions | |
void | Finish (uoffset_t root, const char *file_identifier, bool size_prefix) |
FlatBufferBuilder (const FlatBufferBuilder &) | |
FlatBufferBuilder & | operator= (const FlatBufferBuilder &) |
Protected Attributes | |
vector_downward | buf_ |
bool | dedup_vtables_ |
bool | finished |
bool | force_defaults_ |
voffset_t | max_voffset_ |
size_t | minalign_ |
bool | nested |
uoffset_t | num_field_loc |
StringOffsetMap * | string_pool |
Private Member Functions | |
template<typename T > | |
Offset< Vector< const T * > > | EndVectorOfStructs (size_t vector_size) |
template<typename T > | |
T * | StartVectorOfStructs (size_t vector_size) |
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.
Definition at line 727 of file flatbuffers.h.
|
protected |
Definition at line 1631 of file flatbuffers.h.
|
inlineexplicit |
Default constructor for FlatBufferBuilder.
[in] | initial_size | The initial size of the buffer, in bytes. Defaults to 1024 . |
[in] | allocator | An Allocator to use. Defaults to a new instance of a DefaultAllocator . |
[in] | own_allocator | Whether the builder/vector should own the allocator. Defaults to / false . |
[in] | buffer_minalign | Force the buffer to be aligned to the given minimum alignment upon reallocation. Only needed if you intend to store types with custom alignment AND you wish to read the buffer in-place directly after creation. |
Definition at line 740 of file flatbuffers.h.
|
inline |
Definition at line 757 of file flatbuffers.h.
|
protected |
|
inline |
Reset all the state in this FlatBufferBuilder so it can be reused to construct another buffer.
Definition at line 768 of file flatbuffers.h.
|
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 . |
Definition at line 1120 of file flatbuffers.h.
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. |
Definition at line 1144 of file flatbuffers.h.
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. |
Definition at line 1153 of file flatbuffers.h.
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. |
Definition at line 1162 of file flatbuffers.h.
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 . |
Definition at line 1058 of file flatbuffers.h.
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. |
Definition at line 1070 of file flatbuffers.h.
Store a string in the buffer, which is null-terminated.
[in] | str | A char pointer to a C-string to add to the buffer. |
Definition at line 1077 of file flatbuffers.h.
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. |
Definition at line 1084 of file flatbuffers.h.
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. |
Definition at line 1102 of file flatbuffers.h.
|
inline |
Store a string in the buffer, which can contain any binary data.
[in] | str | A const reference to a std::string like type with support of T::c_str() and T::length() to store in the buffer. |
Definition at line 1110 of file flatbuffers.h.
|
inline |
Write a struct by itself, typically to be part of a union.
Definition at line 1540 of file flatbuffers.h.
|
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. |
Definition at line 1514 of file flatbuffers.h.
|
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. |
Definition at line 1534 of file flatbuffers.h.
|
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. Definition at line 1198 of file flatbuffers.h.
|
inline |
Definition at line 1220 of file flatbuffers.h.
|
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. Definition at line 1232 of file flatbuffers.h.
|
inline |
Definition at line 1239 of file flatbuffers.h.
|
inline |
Serialize values returned by a function into a FlatBuffer vector
. This is a convenience function that takes care of iteration for you.
T | The data type of the std::vector elements. |
f | A function that takes the current iteration 0..vector_size-1 and returns any type that you can construct a FlatBuffers vector out of. |
Offset
into the serialized data indicating where the vector is stored. Definition at line 1256 of file flatbuffers.h.
|
inline |
Serialize values returned by a function into a FlatBuffer vector
. This is a convenience function that takes care of iteration for you.
T | The data type of the std::vector elements. |
f | A function that takes the current iteration 0..vector_size-1, and the state parameter returning any type that you can construct a FlatBuffers vector out of. |
state | State passed to f. |
Offset
into the serialized data indicating where the vector is stored. Definition at line 1275 of file flatbuffers.h.
|
inline |
Serialize an array of native structs into a FlatBuffer vector
.
T | The data type of the struct array elements. |
S | The data type of the native struct array elements. |
[in] | v | A pointer to the array of type S 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. Definition at line 1317 of file flatbuffers.h.
|
inline |
Serialize a std::vector
of native structs into a FlatBuffer vector
.
T | The data type of the std::vector struct elements. |
S | The data type of the std::vector native struct elements. |
[in] |
Definition at line 1389 of file flatbuffers.h.
|
inline |
Serialize a std::vector
of native structs into a FlatBuffer vector
in sorted order.
T | The data type of the std::vector struct elements. |
S | The data type of the std::vector native struct elements. |
[in] |
Definition at line 1426 of file flatbuffers.h.
|
inline |
Serialize an array of native structs into a FlatBuffer vector
in sorted order.
T | The data type of the struct array elements. |
S | The data type of the native struct array elements. |
[in] | v | A pointer to the array of type S 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. Definition at line 1455 of file flatbuffers.h.
|
inline |
Serialize a std::vector
of structs into a FlatBuffer vector
in sorted order.
T | The data type of the std::vector struct elements. |
[in] |
Definition at line 1413 of file flatbuffers.h.
|
inline |
Serialize an array of structs into a FlatBuffer vector
in sorted order.
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. Definition at line 1440 of file flatbuffers.h.
|
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. Definition at line 1488 of file flatbuffers.h.
|
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. Definition at line 1502 of file flatbuffers.h.
|
inline |
Serialize a std::vector<std::string>
into a FlatBuffer vector
. This is a convenience function for a common case.
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. Definition at line 1287 of file flatbuffers.h.
|
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. Definition at line 1302 of file flatbuffers.h.
|
inline |
Serialize an array of structs into a FlatBuffer vector
.
T | The data type of the struct array elements. |
[in] | f | A function that takes the current iteration 0..vector_size-1 and a pointer to the struct that must be filled. |
Offset
into the serialized data indicating where the vector is stored. This is mostly useful when flatbuffers are generated with mutation accessors. Definition at line 1336 of file flatbuffers.h.
|
inline |
Serialize an array of structs into a FlatBuffer vector
.
T | The data type of the struct array elements. |
[in] | f | A function that takes the current iteration 0..vector_size-1, a pointer to the struct that must be filled and the state argument. |
[in] | state | Arbitrary state to pass to f. |
Offset
into the serialized data indicating where the vector is stored. This is mostly useful when flatbuffers are generated with mutation accessors. Definition at line 1358 of file flatbuffers.h.
|
inline |
Serialize a std::vector
of structs into a FlatBuffer vector
.
T | The data type of the std::vector struct elements. |
[in] |
Definition at line 1375 of file flatbuffers.h.
|
inline |
By default vtables are deduped in order to save space.
[in] | bool | dedup When set to true , dedup vtables. |
Definition at line 838 of file flatbuffers.h.
|
inlineprivate |
Definition at line 1645 of file flatbuffers.h.
|
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. |
Definition at line 1554 of file flatbuffers.h.
|
inlineprotected |
Definition at line 1576 of file flatbuffers.h.
|
inline |
Finish a buffer with a 32 bit size field pre-fixed (size of the buffer following the size field). These buffers are NOT compatible with standard buffers created by Finish, i.e. you can't call GetRoot on them, you have to use GetSizePrefixedRoot instead. All >32 bit quantities in this buffer will be aligned when the whole size pre-fixed buffer is aligned. These kinds of buffers are useful for creating a stream of FlatBuffers.
Definition at line 1566 of file flatbuffers.h.
|
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. |
Definition at line 834 of file flatbuffers.h.
|
inline |
get the minimum alignment this buffer needs to be accessed properly. This is only known once all elements have been written (after you call Finish()). You can use this information if you need to embed a FlatBuffer in some other buffer, such that you can later read it without first having to copy it into its own buffer.
Definition at line 815 of file flatbuffers.h.
|
inline |
Get the serialized buffer (after you call Finish()
).
uint8_t
pointer to the FlatBuffer data inside the buffer. Definition at line 784 of file flatbuffers.h.
|
inline |
Get a pointer to an unfinished buffer.
uint8_t
pointer to the unfinished buffer. Definition at line 791 of file flatbuffers.h.
|
inline |
The current size of the serialized buffer, counting from the end.
uoffset_t
with the current size of the buffer. Definition at line 779 of file flatbuffers.h.
|
protected |
|
inline |
Get the released DetachedBuffer.
DetachedBuffer
that owns the buffer and its allocator. Definition at line 805 of file flatbuffers.h.
|
inline |
Get the released pointer to the serialized buffer.
FlatBuffer
that owns the buffer and its allocator and behaves similar to a unique_ptr
with a deleter. Deprecated: use Release() instead Definition at line 798 of file flatbuffers.h.
|
inline |
Definition at line 761 of file flatbuffers.h.
|
inlineprivate |
Definition at line 1637 of file flatbuffers.h.
|
protected |
Definition at line 1598 of file flatbuffers.h.
|
protected |
Definition at line 1617 of file flatbuffers.h.
|
protected |
Definition at line 1611 of file flatbuffers.h.
|
protected |
Definition at line 1615 of file flatbuffers.h.
|
static |
The length of a FlatBuffer file header.
Definition at line 1548 of file flatbuffers.h.
|
protected |
Definition at line 1605 of file flatbuffers.h.
|
protected |
Definition at line 1613 of file flatbuffers.h.
|
protected |
Definition at line 1608 of file flatbuffers.h.
|
protected |
Definition at line 1602 of file flatbuffers.h.
|
protected |
Definition at line 1632 of file flatbuffers.h.