Documentation
¶
Overview ¶
Package flatbuf reads flatbuffers, by hand, from untrusted bytes, and builds them (Builder).
A Vortex file writes its flatbuffers with finish_minimal: no size prefix and no file identifier (vortex-array/src/flatbuffers/traits.rs). The root offset is the first four bytes.
Every offset is checked against the buffer before it is used, so a hostile buffer gives an *Error carrying the offending offset, never a panic and never a read out of bounds. Vectors are views over the buffer: no allocation is made from a length read in the buffer, except the slices of scalars that are bounded by the buffer size itself.
Field ids follow the declaration order of the table in the .fbs file; the caller passes a negative-free constant. A union occupies two ids: its type, then its value.
Index ¶
- type Builder
- func (b *Builder) Bytes(v []byte) Off
- func (b *Builder) EndTable() Off
- func (b *Builder) Finish(root Off) []byte
- func (b *Builder) Offsets(v []Off) Off
- func (b *Builder) Ref(id int, off Off)
- func (b *Builder) Reset()
- func (b *Builder) StartTable(n int)
- func (b *Builder) String(s string) Off
- func (b *Builder) Structs(size, align int, raw []byte) Off
- func (b *Builder) Uint8(id int, v, def uint8)
- func (b *Builder) Uint16(id int, v, def uint16)
- func (b *Builder) Uint16s(v []uint16) Off
- func (b *Builder) Uint32(id int, v, def uint32)
- func (b *Builder) Uint32s(v []uint32) Off
- func (b *Builder) Uint64(id int, v, def uint64)
- func (b *Builder) Union(id int, typ uint8, value Off)
- type Error
- type Off
- type Table
- func (t Table) AppendUint16s(dst []uint16, id int) ([]uint16, error)
- func (t Table) Bool(id int, def bool) (bool, error)
- func (t Table) Bytes(id int) ([]byte, bool, error)
- func (t Table) Has(id int) bool
- func (t Table) Int8(id int, def int8) (int8, error)
- func (t Table) String(id int) (string, bool, error)
- func (t Table) Strings(id int) (Vector, error)
- func (t Table) Structs(id, size int) (Vector, error)
- func (t Table) Table(id int) (Table, bool, error)
- func (t Table) Tables(id int) (Vector, error)
- func (t Table) Uint8(id int, def uint8) (uint8, error)
- func (t Table) Uint16(id int, def uint16) (uint16, error)
- func (t Table) Uint16s(id int) ([]uint16, error)
- func (t Table) Uint32(id int, def uint32) (uint32, error)
- func (t Table) Uint32s(id int) ([]uint32, error)
- func (t Table) Uint64(id int, def uint64) (uint64, error)
- func (t Table) Union(id int) (uint8, Table, error)
- type Vector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder writes a flatbuffer back to front, like the reference implementation does. It finishes a buffer "minimal": no size prefix and no file identifier. A table is written between StartTable and EndTable, and everything it points to (child tables, strings, vectors) before StartTable. A Builder is reused with Reset, and then allocates nothing once its buffer has grown to the size of the largest message.
func NewBuilder ¶
NewBuilder returns a Builder with room for size bytes.
func (*Builder) EndTable ¶
EndTable writes the vtable and returns the table. A vtable equal to one already written is not written again: the table points to the first one, as the reference builder does, so a message of many tables of the same shape (the fields of a schema, say) carries one vtable.
func (*Builder) Finish ¶
Finish writes the offset of the root table, and returns the message. It stays valid until the next Reset.
func (*Builder) StartTable ¶
StartTable begins a table of n fields (the ids 0 to n-1). A union takes two ids.
func (*Builder) Structs ¶
Structs writes a vector of structs of size bytes each, with the given alignment. raw holds the structs in order, already in little-endian: its length is a multiple of size.
func (*Builder) Uint8 ¶
Uint8 sets a field of one byte (also a bool or an enum). A field equal to its default is left out.
type Error ¶
type Error struct {
Msg string // what was wrong with it
Off int // the offset that was read, or that a computed offset led to
}
Error is a bounds violation in a buffer.
type Off ¶
type Off uint32
Off is the position of a table, a vector or a string that a Builder has written: its distance from the end of the buffer. It is only meaningful for the Builder that returned it.
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table is a view of one flatbuffers table.
func Root ¶
Root returns the root table of buf. maxDepth bounds how many tables may be nested below (and including) the root; the root is at depth 1.
func (Table) AppendUint16s ¶ added in v0.1.1
AppendUint16s appends a vector of uint16 to dst: in its memory when it has room.
func (Table) Bytes ¶
Bytes returns a vector of bytes (or a string's bytes). It aliases the buffer. The bool is false when the field is absent.
func (Table) Has ¶
Has reports whether the table has the field. A field with a "= null" default is optional: Has tells it apart from a field set to zero.
func (Table) Uint8 ¶
Uint8 returns the field, or def when it is absent. Bools and enums of a byte use it too.
func (Table) Uint16s ¶
Uint16s returns a vector of uint16 as a new slice, its size bounded by the buffer.
func (Table) Uint32s ¶
Uint32s returns a vector of uint32 as a new slice, its size bounded by the buffer.
type Vector ¶
type Vector struct {
// contains filtered or unexported fields
}
Vector is a view of a vector of tables, strings or structs, built by Tables, Strings or Structs.