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§
Required Methods§
Sourcefn pack(
&self,
builder: &mut FlatBufferBuilder<'a>,
) -> WIPOffset<Self::TableType>
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.
Sourcefn unpack(data: &'a [u8]) -> Result<Self, InvalidFlatbuffer>where
Self: Sized,
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.