autobahn.flatbuffers¶
Submodules¶
Attributes¶
Classes¶
Functions¶
|
Return the exact git version of the vendored FlatBuffers runtime. |
Package Contents¶
- class Builder(initialSize=1024)[source]¶
Bases:
objectA 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¶
CreateSharedString checks if the string is already written to the buffer
before calling CreateString.
- CreateString(s, encoding='utf-8', errors='strict')[source]¶
CreateString writes a null-terminated byte string as a vector.
- 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¶
- 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.
- 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.
- PrependFloat32(x)[source]¶
Prepend a float32 to the Builder buffer.
Note: aligns and checks for space.
- PrependFloat64(x)[source]¶
Prepend a float64 to the Builder buffer.
Note: aligns and checks for space.
- PrependSOffsetTRelative(off)[source]¶
PrependSOffsetTRelative prepends an SOffsetT, relative to where it
will be written.
- 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.
- PrependUint32(x)[source]¶
Prepend an uint32 to the Builder buffer.
Note: aligns and checks for space.
- PrependUint64(x)[source]¶
Prepend an uint64 to the Builder buffer.
Note: aligns and checks for space.
- 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.
- 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:
objectTable wraps a byte slice and provides read access to its data.
The variable Pos indicates the root of the FlatBuffers object therein.
- Bytes¶
- GetArrayAsNumpy(flags, off, length)[source]¶
GetArrayAsNumpy returns the array with fixed width that starts at Vector(offset)
with length length as a numpy array with the type specified by flags. The array is a view into Bytes so modifying the returned will modify Bytes in place.
- 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.
- Offset(vtableOffset)[source]¶
Offset provides access into the Table’s vtable.
Deprecated fields are ignored by checking the vtable’s length.
- Pos¶
- 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')¶
- version() tuple[int, int, int, int | None, str | None][source]¶
Return the exact git version of the vendored FlatBuffers runtime.
Handles:
“v25.9.23” -> (25, 9, 23, None, None) # Release (Named Tag, CalVer Year.Month.Day)
“v25.9.23-71” -> (25, 9, 23, 71, None) # 71 commits ahead of the Release v25.9.23
“v25.9.23-71-g19b2300f” -> (25, 9, 23, 71, “19b2300f”) # dito, with Git commit hash