zlmdb.flatbuffers

Submodules

Attributes

Classes

Builder

A Builder is used to construct one or more FlatBuffers.

Table

Table wraps a byte slice and provides read access to its data.

Functions

version(→ tuple[int, int, int, int | None, str | None])

Return the exact git version of the vendored FlatBuffers runtime.

Package Contents

class Builder(initialSize=1024)[source]

Bases: object

A Builder is used to construct one or more FlatBuffers.

Typically, Builder objects will be used from code generated by the flatc compiler.

A Builder constructs byte buffers in a last-first manner for simplicity and performance during reading.

Internally, a Builder is a state machine for creating FlatBuffer objects.

It holds the following internal state:
  • Bytes: an array of bytes.

  • current_vtable: a list of integers.

  • vtables: a hash of vtable entries.

Bytes

The internal bytearray for the Builder.

finished

A boolean determining if the Builder has been finalized.

Bytes
CreateByteVector(x)[source]

CreateString writes a byte vector.

CreateNumpyVector(x)[source]

CreateNumpyVector writes a numpy array into the buffer.

CreateString(s, encoding='utf-8', errors='strict')[source]

CreateString writes a null-terminated byte string as a vector.

EndObject()[source]

EndObject writes data necessary to finish object construction.

EndVector()[source]

EndVector writes data necessary to finish vector construction.

Finish(rootTable, file_identifier=None)[source]

Finish finalizes a buffer, pointing to the given rootTable.

FinishSizePrefixed(rootTable, file_identifier=None)[source]

Finish finalizes a buffer, pointing to the given rootTable, with the size prefixed.

ForceDefaults(forceDefaults)[source]

In order to save space, fields that are set to their default value don’t get serialized into the buffer. Forcing defaults provides a way to manually disable this optimization. When set to True, will always serialize default values.

Head()[source]

Get the start of useful data in the underlying byte buffer.

Note: unlike other functions, this value is interpreted as from the left.

MAX_BUFFER_SIZE = 2147483648
Offset()[source]

Offset relative to the end of the buffer.

Output()[source]

Return the portion of the buffer that has been used for writing data.

This is the typical way to access the FlatBuffer data inside the builder. If you try to access Builder.Bytes directly, you would need to manually index it with Head(), since the buffer is constructed backwards.

It raises BuilderNotFinishedError if the buffer has not been finished with Finish.

Pad(n)[source]

Pad places zeros at the current offset.

Place(x, flags)[source]

Place prepends a value specified by flags to the Builder, without checking for available space.

PlaceSOffsetT(x)[source]

PlaceSOffsetT prepends a SOffsetT to the Builder, without checking for space.

PlaceUOffsetT(x)[source]

PlaceUOffsetT prepends a UOffsetT to the Builder, without checking for space.

PlaceVOffsetT(x)[source]

PlaceVOffsetT prepends a VOffsetT to the Builder, without checking for space.

Prep(size, additionalBytes)[source]

Prep prepares to write an element of size after additional_bytes have been written, e.g. if you write a string, you need to align such the int length field is aligned to SizeInt32, and the string data follows it directly. If all you need to do is align, additionalBytes will be 0.

Prepend(flags, off)[source]
PrependBool(x)[source]

Prepend a bool to the Builder buffer.

Note: aligns and checks for space.

PrependBoolSlot(*args)[source]
PrependByte(x)[source]

Prepend a byte to the Builder buffer.

Note: aligns and checks for space.

PrependByteSlot(*args)[source]
PrependFloat32(x)[source]

Prepend a float32 to the Builder buffer.

Note: aligns and checks for space.

PrependFloat32Slot(*args)[source]
PrependFloat64(x)[source]

Prepend a float64 to the Builder buffer.

Note: aligns and checks for space.

PrependFloat64Slot(*args)[source]
PrependInt16(x)[source]

Prepend an int16 to the Builder buffer.

Note: aligns and checks for space.

PrependInt16Slot(*args)[source]
PrependInt32(x)[source]

Prepend an int32 to the Builder buffer.

Note: aligns and checks for space.

PrependInt32Slot(*args)[source]
PrependInt64(x)[source]

Prepend an int64 to the Builder buffer.

Note: aligns and checks for space.

PrependInt64Slot(*args)[source]
PrependInt8(x)[source]

Prepend an int8 to the Builder buffer.

Note: aligns and checks for space.

PrependInt8Slot(*args)[source]
PrependSOffsetTRelative(off)[source]

PrependSOffsetTRelative prepends an SOffsetT, relative to where it will be written.

PrependSlot(flags, o, x, d)[source]
PrependStructSlot(v, x, d)[source]

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.

PrependUOffsetTRelative(off)[source]

Prepends an unsigned offset into vector data, relative to where it will be written.

PrependUOffsetTRelativeSlot(o, x, d)[source]

PrependUOffsetTRelativeSlot prepends an 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.

PrependUint16(x)[source]

Prepend an uint16 to the Builder buffer.

Note: aligns and checks for space.

PrependUint16Slot(*args)[source]
PrependUint32(x)[source]

Prepend an uint32 to the Builder buffer.

Note: aligns and checks for space.

PrependUint32Slot(*args)[source]
PrependUint64(x)[source]

Prepend an uint64 to the Builder buffer.

Note: aligns and checks for space.

PrependUint64Slot(*args)[source]
PrependUint8(x)[source]

Prepend an uint8 to the Builder buffer.

Note: aligns and checks for space.

PrependUint8Slot(*args)[source]
PrependVOffsetT(x)[source]
Slot(slotnum)[source]

Slot sets the vtable key voffset to the current location in the buffer.

StartObject(numfields)[source]

StartObject initializes bookkeeping for writing a new object.

StartVector(elemSize, numElems, alignment)[source]

StartVector initializes bookkeeping for writing a new vector.

A vector has the following format:
  • <UOffsetT: number of elements in this vector>

  • <T: data>+, where T is the type of elements of this vector.

WriteVtable()[source]

WriteVtable serializes the vtable for the current object, if needed.

Before writing out the vtable, this checks pre-existing vtables for equality to this one. If an equal vtable is found, point the object to the existing vtable and return.

Because vtable values are sensitive to alignment of object data, not all logically-equal vtables will be deduplicated.

A vtable has the following format:

<VOffsetT: size of the vtable in bytes, including this value> <VOffsetT: size of the object in bytes, including the vtable offset> <VOffsetT: offset for a field> * N, where N is the number of fields

in the schema for this type. Includes deprecated fields.

Thus, a vtable is made of 2 + N elements, each VOffsetT bytes wide.

An object has the following format:

<SOffsetT: offset to this object’s vtable (may be negative)> <byte: data>+

__Finish(rootTable, sizePrefix, file_identifier=None)[source]

Finish finalizes a buffer, pointing to the given rootTable.

__slots__ = ('Bytes', 'current_vtable', 'head', 'minalign', 'objectEnd', 'vtables', 'nested',...

Maximum buffer size constant, in bytes.

Builder will never allow it’s buffer grow over this size. Currently equals 2Gb.

assertNested()[source]

Check that we are in the process of building an object.

assertNotNested()[source]

Check that no other objects are being built while making this object. If not, raise an exception.

assertStructIsInline(obj)[source]

Structs are always stored inline, so need to be created right where they are used. You’ll get this error if you created it elsewhere.

current_vtable = None
finished = False
forceDefaults = False
growByteBuffer()[source]

Doubles the size of the byteslice, and copies the old data towards the end of the new buffer (since we build the buffer backwards).

head
minalign = 1
nested = False
objectEnd = None
vtables
class Table(buf, pos)[source]

Bases: object

Table wraps a byte slice and provides read access to its data.

The variable Pos indicates the root of the FlatBuffers object therein.

Bytes
Get(flags, off)[source]

Get retrieves a value of the type specified by flags at the given offset.

GetSlot(slot, d, validator_flags)[source]
GetVOffsetTSlot(slot, d)[source]

GetVOffsetTSlot retrieves the VOffsetT that the given vtable location points to. If the vtable value is zero, the default value d will be returned.

GetVectorAsNumpy(flags, off)[source]

GetVectorAsNumpy returns the vector that starts at Vector(off) as a numpy array with the type specified by flags. The array is a view into Bytes, so modifying the returned array will modify Bytes in place.

Indirect(off)[source]

Indirect retrieves the relative offset stored at offset.

Offset(vtableOffset)[source]

Offset provides access into the Table’s vtable.

Deprecated fields are ignored by checking the vtable’s length.

Pos
String(off)[source]

String gets a string from data stored inside the flatbuffer.

Union(t2, off)[source]

Union initializes any Table-derived type to point to the union at the given offset.

Vector(off)[source]

Vector retrieves the start of data of the vector whose offset is stored at “off” in this object.

VectorLen(off)[source]

VectorLen retrieves the length of the vector whose offset is stored at “off” in this object.

__slots__ = ('Bytes', 'Pos')
__git_version__ = 'v25.9.23'[source]
version() tuple[int, int, int, int | None, str | None][source]

Return the exact git version of the vendored FlatBuffers runtime.

Handles:

  1. “v25.9.23” -> (25, 9, 23, None, None) # Release (Named Tag, CalVer Year.Month.Day)

  2. “v25.9.23-71” -> (25, 9, 23, 71, None) # 71 commits ahead of the Release v25.9.23

  3. “v25.9.23-71-g19b2300f” -> (25, 9, 23, 71, “19b2300f”) # dito, with Git commit hash