Struct flatbuffers::Builder
[−]
[src]
pub struct Builder { // some fields omitted }
Flatbuffer builder.
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 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 finish(&mut self, root_table: UOffsetT)
Finalize a buffer, pointing to the given root_table
.
fn get_bytes(&self) -> &[u8]
Consume the builder and return the finished flatbuffer.
fn len(&self) -> usize
Returns the length of the buffer.
fn swap_out(&mut self, new_buffer: Vec<u8>) -> Vec<u8>
Returns the current finished 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 offset(&self) -> usize
Offset relative to the end 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.
impl Builder
[src]
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).