pub struct FlatBufferBuilder<'fbb> { /* private fields */ }
Expand description

FlatBufferBuilder builds a FlatBuffer through manipulating its internal state. It has an owned Vec<u8> that grows as needed (up to the hardcoded limit of 2GiB, which is set by the FlatBuffers format).

Implementations§

Create a FlatBufferBuilder that is ready for writing.

👎Deprecated since 0.8.5: replaced with with_capacity

Create a FlatBufferBuilder that is ready for writing, with a ready-to-use capacity of the provided size.

The maximum valid value is FLATBUFFERS_MAX_BUFFER_SIZE.

Create a FlatBufferBuilder that is ready for writing, reusing an existing vector.

Reset the FlatBufferBuilder internal state. Use this method after a call to a finish function in order to re-use a FlatBufferBuilder.

This function is the only way to reset the finished state and start again.

If you are using a FlatBufferBuilder repeatedly, make sure to use this function, because it re-uses the FlatBufferBuilder’s existing heap-allocated Vec<u8> internal buffer. This offers significant speed improvements as compared to creating a new FlatBufferBuilder for every new object.

Destroy the FlatBufferBuilder, returning its internal byte vector and the index into it that represents the start of valid data.

Push a Push’able value onto the front of the in-progress data.

This function uses traits to provide a unified API for writing scalars, tables, vectors, and WIPOffsets.

Push a Push’able value onto the front of the in-progress data, and store a reference to it in the in-progress vtable. If the value matches the default, then this is a no-op.

Push a Push’able value onto the front of the in-progress data, and store a reference to it in the in-progress vtable.

Retrieve the number of vtables that have been serialized into the FlatBuffer. This is primarily used to check vtable deduplication.

Start a Table write.

Asserts that the builder is not in a nested state.

Users probably want to use push_slot to add values after calling this.

End a Table write.

Asserts that the builder is in a nested state.

Start a Vector write.

Asserts that the builder is not in a nested state.

Most users will prefer to call create_vector. Speed optimizing users who choose to create vectors manually using this function will want to use push to add values.

End a Vector write.

Note that the num_elems parameter is the number of written items, not the byte count.

Asserts that the builder is in a nested state.

Create a utf8 string.

The wire format represents this as a zero-terminated byte vector.

Create a zero-terminated byte vector.

Create a vector of Push-able objects.

Speed-sensitive users may wish to reduce memory usage by creating the vector manually: use start_vector, push, and end_vector.

Create a vector of Push-able objects.

Speed-sensitive users may wish to reduce memory usage by creating the vector manually: use start_vector, push, and end_vector.

Set whether default values are stored.

In order to save space, fields that are set to their default value aren’t stored in the buffer. Setting force_defaults to true disables this optimization.

By default, force_defaults is false.

Get the byte slice for the data that has been written, regardless of whether it has been finished.

Get the byte slice for the data that has been written after a call to one of the finish functions.

Panics

Panics if the buffer is not finished.

Returns a mutable view of a finished buffer and location of where the flatbuffer starts. Note that modifying the flatbuffer data may corrupt it.

Panics

Panics if the flatbuffer is not finished.

Assert that a field is present in the just-finished Table.

This is somewhat low-level and is mostly used by the generated code.

Finalize the FlatBuffer by: aligning it, pushing an optional file identifier on to it, pushing a size prefix on to it, and marking the internal state of the FlatBufferBuilder as finished. Afterwards, users can call finished_data to get the resulting data.

Finalize the FlatBuffer by: aligning it, pushing an optional file identifier on to it, and marking the internal state of the FlatBufferBuilder as finished. Afterwards, users can call finished_data to get the resulting data.

Finalize the FlatBuffer by: aligning it and marking the internal state of the FlatBufferBuilder as finished. Afterwards, users can call finished_data to get the resulting data.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.