Skip to main content

FlatbufferPack

Trait FlatbufferPack 

Source
pub trait FlatbufferPack<'a> {
    type TableType: Follow<'a> + 'a;

    // Required methods
    fn pack(
        &self,
        builder: &mut FlatBufferBuilder<'a>,
    ) -> WIPOffset<Self::TableType>;
    fn unpack(data: &'a [u8]) -> Result<Self, InvalidFlatbuffer>
       where Self: Sized;
}
Expand description

Trait defining the common interface for FlatBuffer-compatible types.

This trait allows any type implementing it to:

  • Pack itself into a FlatBuffer builder, producing an flatbuffer offset object.
  • Unpack itself from a serialized byte buffer back into a flatbuffer struct/enum.

Required Associated Types§

Source

type TableType: Follow<'a> + 'a

The generated FlatBuffer table type corresponding to this flatbuffer struct/enum.

Required Methods§

Source

fn pack( &self, builder: &mut FlatBufferBuilder<'a>, ) -> WIPOffset<Self::TableType>

Packs the native struct into a FlatBuffer builder.

Returns a WIPOffset object pointing to the serialized object within the builder.

Source

fn unpack(data: &'a [u8]) -> Result<Self, InvalidFlatbuffer>
where Self: Sized,

Unpacks the FlatBuffer binary data into a native struct instance.

§Errors

Returns flatbuffers::InvalidFlatbuffer if the input buffer is malformed or missing required fields.

Implementors§