Crate flatbuffers
source ·Expand description
FlatBuffers
A library for memory-efficient serialization of data.
This crate provides runtime support for the FlatBuffers format in the Rust programming language.
To use this crate, first generate code with the flatc
compiler, as described here: https://google.github.io/flatbuffers/
Then, include that code into your project.
Finally, add this crate to your Cargo.toml
.
At this time, Rust support is experimental, and APIs may change between minor versions.
At this time, to generate Rust code, you will need the latest master
version of flatc
, available from here: https://github.com/google/flatbuffers
(On OSX, you can install FlatBuffers from HEAD
with the Homebrew package manager.)
Re-exports
pub use bitflags;
Structs
ForwardsSOffset is used by Follow to traverse a FlatBuffer: the pointer
is incremented by the negative of the value contained in this type.
FileIdentifier is used by Follow to traverse a FlatBuffer: the pointer is
dereferenced into a byte slice, whose bytes are the file identifer value.
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).FollowStart wraps a Follow impl in a struct type. This can make certain
programming patterns more ergonomic.
ForwardsUOffset is used by Follow to traverse a FlatBuffer: the pointer
is incremented by the value contained in this type.
ForwardsVOffset is used by Follow to traverse a FlatBuffer: the pointer
is incremented by the value contained in this type.
SkipFileIdentifier is used by Follow to traverse a FlatBuffer: the pointer
is incremented by a fixed constant in order to skip over the file
identifier value.
SkipRootOffset is used by Follow to traverse a FlatBuffer: the pointer is
incremented by a fixed constant in order to skip over the root offset value.
SkipSizePrefix is used by Follow to traverse a FlatBuffer: the pointer is
incremented by a fixed constant in order to skip over the size prefix value.
TableFinishedWIPOffset marks a WIPOffset as being for a finished table.
TableUnfinishedWIPOffset marks a WIPOffset as being for an unfinished table.
UnionWIPOffset marks a WIPOffset as being for a union value.
VTableWIPOffset marks a WIPOffset as being for a vtable.
An iterator over a
Vector
.Carries the verification state. Should not be reused between tables.
WIPOffset contains an UOffsetT with a special meaning: it is the location of
data relative to the end of an in-progress FlatBuffer. The
FlatBufferBuilder uses this to track the location of objects in an absolute
way. The impl of Push converts a WIPOffset into a ForwardsUOffset.
Enums
Traces the location of data errors. Not populated for Dos detecting errors.
Useful for MissingRequiredField and Utf8Error in particular, though
the other errors should not be producible by correct flatbuffers implementations.
Describes how a flatuffer is invalid and, for data errors, roughly where. No extra tracing
information is given for DoS detecting errors since it will probably be a lot.
Constants
Traits
Trait for values that must be stored in little-endian byte order, but
might be represented in memory as big-endian. Every type that implements
EndianScalar is a valid FlatBuffers scalar value.
Follow is a trait that allows us to access FlatBuffers in a declarative,
type safe, and fast way. They compile down to almost no code (after
optimizations). Conceptually, Follow lifts the offset-based access
patterns of FlatBuffers data into the type system. This trait is used
pervasively at read time, to access tables, vtables, vectors, strings, and
all other data. At this time, Follow is not utilized much on the write
path.
Trait to abstract over functionality needed to write values (either owned
or referenced). Used in FlatBufferBuilder and implemented for generated
types.
Functions
Returns true if data contains a prefix of
ident
Place an EndianScalar into the provided mutable byte slice. Performs
endian conversion, if necessary.
Place an array of EndianScalar into the provided mutable byte slice. Performs
endian conversion, if necessary.
Safety
Read an EndianScalar from the provided byte slice. Performs endian
conversion, if necessary.
Read an EndianScalar from the provided byte slice at the specified location.
Performs endian conversion, if necessary.
Gets the root of the Flatbuffer, verifying it first with default options.
Note that verification is an experimental feature and may not be maximally performant or
catch every error (though that is the goal). See the
_unchecked
variants for previous
behavior.Gets root for a trusted Flatbuffer.
Gets the root of the Flatbuffer, verifying it first with given options.
Note that verification is an experimental feature and may not be maximally performant or
catch every error (though that is the goal). See the
_unchecked
variants for previous
behavior.Gets the root of a size prefixed Flatbuffer, verifying it first with default options.
Note that verification is an experimental feature and may not be maximally performant or
catch every error (though that is the goal). See the
_unchecked
variants for previous
behavior.Gets root for a trusted, size prefixed, Flatbuffer.
Gets the root of a size prefixed Flatbuffer, verifying it first with given options.
Note that verification is an experimental feature and may not be maximally performant or
catch every error (though that is the goal). See the
_unchecked
variants for previous
behavior.