Struct flatbuffers::Builder
[−]
[src]
pub struct Builder {
// some fields omitted
}Builder provides functions to build Flatbuffer data.
A Builder constructs byte buffers in a last-first manner for simplicity and performance.
Methods
impl Builder[src]
fn with_capacity(size: usize) -> Self
Start a new FlatBuffer Builder backed by a buffer with an
initial capacity of size.
fn start_object(&mut self, num_fields: usize)
Start encoding a new object in the buffer.
fn end_object(&mut self) -> UOffsetT
finish off writing the object that is under construction.
Returns the offset of the object in the inside the buffer.
fn read_object(&self, offset: UOffsetT) -> Table
Read a completed object at offset.
The offset is the UOffsetT returned by end_object.
fn read_table(&self, offset: UOffsetT) -> Table
Read a completed object at offset.
The offset is the UOffsetT returned by end_table.
fn start_vector(&mut self, elem_size: usize, num_elems: usize, alignment: usize)
Initializes bookkeeping for writing a new vector.
fn end_vector(&mut self) -> UOffsetT
finish off writing the current vector.
fn create_string(&mut self, value: &str) -> UOffsetT
Create a string in the buffer from an already encoded UTF-8 String.
fn create_vector(&mut self, value: &[u8]) -> UOffsetT
Create a vector in the buffer from an already encoded byte vector.
fn create_uoffset_vector(&mut self, value: &[UOffsetT]) -> UOffsetT
Create a vector of UOffsetT in the buffer.
This function will encode the values to LittleEndian.
fn finish_table(&mut self, root_table: UOffsetT) -> UOffsetT
Finalize a table, pointing to the given root_table.
fn get_bytes(&self) -> &[u8]
Get a reference to the underlying buffer.
Buffer starts from the first byte of useful data
i.e. &[pos..].
fn swap_out(&mut self, new_buffer: Vec<u8>) -> Vec<u8>
Returns the current buffer and replaces it with
a new_buffer.
Thie function facilitates some reuse of the Builder object.
Use into() if the Builder is no longer required.
fn reset(&mut self)
Resets the builder.
Clears the buffer without resizing. This allows for reuse without allocating new memeory.
fn len(&self) -> usize
Returns the length of the buffer.
fn offset(&self) -> UOffsetT
Offset relative to the end of the buffer.
fn pos(&self) -> usize
Returns the offset relative to the beggining of the buffer.
fn prep(&mut self, size: usize, additional_bytes: usize)
prepare to write an element of size after additional_bytes
have been written.
fn pad(&mut self, n: usize)
pad places zeros at the current offset.
impl Builder[src]
fn put_bool(&mut self, boolean: bool)
Add a bool to the buffer, backwards from the current location.
Doesn't align nor check for space.
fn put_u8(&mut self, byte: u8)
Add a byte to the buffer, backwards from the current location.
Doesn't align nor check for space.
fn put_i8(&mut self, value: i8)
Add a value of type i8 to the buffer, backwards from the current
location. Doesn't align nor check for space.
fn put_u16(&mut self, value: u16)
Add a value of type u16 to the buffer, backwards from the current
location. Doesn't align nor check for space.
fn put_i16(&mut self, value: i16)
Add a value of type i16 to the buffer, backwards from the current
location. Doesn't align nor check for space.
fn put_u32(&mut self, value: u32)
Add a value of type u32 to the buffer, backwards from the current
location. Doesn't align nor check for space.
fn put_i32(&mut self, value: i32)
Add a value of type i32 to the buffer, backwards from the current
location. Doesn't align nor check for space.
fn put_u64(&mut self, value: u64)
Add a value of type u64 to the buffer, backwards from the current
location. Doesn't align nor check for space.
fn put_i64(&mut self, value: i64)
Add a value of type i64 to the buffer, backwards from the current
location. Doesn't align nor check for space.
fn put_f32(&mut self, value: f32)
Add a value of type f32 to the buffer, backwards from the current
location. Doesn't align nor check for space.
fn put_f64(&mut self, value: f64)
Add a value of type f64 to the buffer, backwards from the current
location. Doesn't align nor check for space.
fn put_uoffset(&mut self, value: UOffsetT)
Add a value of type UOffsetT to the buffer, backwards from the
current location. Doesn't align nor check for space.
fn add_bool(&mut self, value: bool)
Add a bool to the buffer, properly aligned, and grows the
buffer (if necessary).
fn add_u8(&mut self, value: u8)
Add a value of type u8 to the buffer, properly aligned, and grows the
buffer (if necessary).
fn add_i8(&mut self, value: i8)
Add a value of type i8 to the buffer, properly aligned, and grows the
buffer (if necessary).
fn add_u16(&mut self, value: u16)
Add a value of type u16 to the buffer, properly aligned, and grows the
buffer (if necessary).
fn add_i16(&mut self, value: i16)
Add a value of type i16 to the buffer, properly aligned, and grows the
buffer (if necessary).
fn add_u32(&mut self, value: u32)
Add a value of type u32 to the buffer, properly aligned, and grows the
buffer (if necessary).
fn add_i32(&mut self, value: i32)
Add a value of type i32 to the buffer, properly aligned, and grows the
buffer (if necessary).
fn add_u64(&mut self, value: u64)
Add a value of type u64 to the buffer, properly aligned, and grows the
buffer (if necessary).
fn add_i64(&mut self, value: i64)
Add a value of type i64 to the buffer, properly aligned, and grows the
buffer (if necessary).
fn add_f32(&mut self, value: f32)
Add a value of type f32 to the buffer, properly aligned, and grows the
buffer (if necessary).
fn add_f64(&mut self, value: f64)
Add a value of type f64 to the buffer, properly aligned, and grows the
buffer (if necessary).
fn add_uoffset(&mut self, value: UOffsetT)
Add a value of type f64 to the buffer, properly aligned, and grows the
buffer (if necessary).
prepends an UOffsetT, relative to where it will be written.
fn slot(&mut self, slot: usize)
Slot sets the vtable key voffset to the current location in the buffer.
fn add_slot_bool(&mut self, o: usize, value: bool, d: bool)
Add a bool onto the object at vtable slot o. If value x equals
default d, then the slot will be set to zero and no other data
will be written.
fn add_slot_u8(&mut self, o: usize, value: u8, d: u8)
Add a value of type u8 onto the object at vtable slot o. If value
x equals default d, then the slot will be set to zero and no other
data will be written.
fn add_slot_i8(&mut self, o: usize, value: i8, d: i8)
Add a value of type i8 onto the object at vtable slot o. If value
x equals default d, then the slot will be set to zero and no other
data will be written.
fn add_slot_u16(&mut self, o: usize, value: u16, d: u16)
Add a value of type u16 onto the object at vtable slot o. If value
x equals default d, then the slot will be set to zero and no other
data will be written.
fn add_slot_i16(&mut self, o: usize, value: i16, d: i16)
Add a value of type i16 onto the object at vtable slot o. If value
x equals default d, then the slot will be set to zero and no other
data will be written.
fn add_slot_u32(&mut self, o: usize, value: u32, d: u32)
Add a value of type u32 onto the object at vtable slot o. If value
x equals default d, then the slot will be set to zero and no other
data will be written.
fn add_slot_i32(&mut self, o: usize, value: i32, d: i32)
Add a value of type i32 onto the object at vtable slot o. If value
x equals default d, then the slot will be set to zero and no other
data will be written.
fn add_slot_u64(&mut self, o: usize, value: u64, d: u64)
Add a value of type u64 onto the object at vtable slot o. If value
x equals default d, then the slot will be set to zero and no other
data will be written.
fn add_slot_i64(&mut self, o: usize, value: i64, d: i64)
Add a value of type i64 onto the object at vtable slot o. If value
x equals default d, then the slot will be set to zero and no other
data will be written.
fn add_slot_f32(&mut self, o: usize, value: f32, d: f32)
Add a value of type f32 onto the object at vtable slot o. If value
x equals default d, then the slot will be set to zero and no other
data will be written.
fn add_slot_f64(&mut self, o: usize, value: f64, d: f64)
Add a value of type f64 onto the object at vtable slot o. If value
x equals default d, then the slot will be set to zero and no other
data will be written.
fn add_slot_uoffset(&mut self, o: usize, value: UOffsetT, d: UOffsetT)
Add a value of type UOffsetT onto the object at vtable slot o. If
value x equals default d, then the slot will be set to zero and no
other data will be written.
prepends an UOffsetT, relative to where it will be written.
fn add_slot_struct(&mut self, o: usize, value: UOffsetT, d: UOffsetT)
PrependStructSlot prepends a struct onto the object at vtable slot o.
Structs are stored inline, so nothing additional is being added.
In generated code, d is always 0.
fn place_u8(&mut self, pos: usize, value: u8)
Place a u8 at pos relative to the beginning
of the underlaying buffer.
fn place_u32(&mut self, pos: usize, value: u32)
Place a u32 with LittleEndian encoding at pos
relative to the beginning of the underlaying buffer.
fn place_i32(&mut self, pos: usize, value: i32)
Place a i32 with LittleEndian encoding at pos
relative to the beginning of the underlaying buffer.
fn place_u64(&mut self, pos: usize, value: u64)
Place a u64 with LittleEndian encoding at pos
relative to the beginning of the underlaying buffer.
fn assert_not_finished(&self)
Check to assert finish has not been called.
fn assert_not_nested(&self)
Check to assert start_object has not been called.
fn assert_nested(&self)
Check to assert start_object has been called.
fn get_u16(&self, pos: usize) -> VOffsetT
Helper method to read a VOffsetT at pos relative to the
beginning of the underlying buffer - this may not be the start
of any useful data. Use with offset() to get the UOffsetT
of useful data.
fn get_32(&self, pos: usize) -> UOffsetT
Helper method to read a UOffsetT at pos relative to the
beginning of the underlying buffer - this may not be the start
of any useful data. Use with offset() to get the UOffsetT
of useful data.
fn grow(&mut self)
Doubles the size of the buffer.
Copies the old data towards the end of the new buffer (since we build the buffer backwards). Max buffer size is 2 Gigabytes - otherwise u16 index values might be invalid.
Trait Implementations
impl Clone for Builder[src]
fn clone(&self) -> Builder
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0
Performs copy-assignment from source. Read more