autobahn.flatbuffers.builder¶
Attributes¶
Exceptions¶
Error caused by not calling Finish before calling Output. |
|
Error caused by causing a Builder to exceed the hardcoded limit of 2 |
|
The number of elements passed to EndVector does not match the number |
|
Error caused by using a Builder to begin an Object when an Object is |
|
Error caused by using a Builder to write Object data when not inside |
|
Error caused by an Offset arithmetic error. |
|
Error caused by using a Builder to write a Struct at a location that |
Classes¶
A Builder is used to construct one or more FlatBuffers. |
Functions¶
|
vtableEqual compares an unwritten vtable to a written vtable. |
Module 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.
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.
- 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',...[source]¶
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.
- 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).
- exception BuilderNotFinishedError[source]¶
Bases:
RuntimeErrorError caused by not calling Finish before calling Output.
- exception BuilderSizeError[source]¶
Bases:
RuntimeErrorError caused by causing a Builder to exceed the hardcoded limit of 2
gigabytes.
- exception EndVectorLengthMismatched[source]¶
Bases:
RuntimeErrorThe number of elements passed to EndVector does not match the number
specified in StartVector.
- exception IsNestedError[source]¶
Bases:
RuntimeErrorError caused by using a Builder to begin an Object when an Object is
already being built.
- exception IsNotNestedError[source]¶
Bases:
RuntimeErrorError caused by using a Builder to write Object data when not inside
an Object.
- exception OffsetArithmeticError[source]¶
Bases:
RuntimeErrorError caused by an Offset arithmetic error.
Probably caused by bad writing of fields. This is considered an unreachable situation in normal circumstances.
- exception StructIsNotInlineError[source]¶
Bases:
RuntimeErrorError caused by using a Builder to write a Struct at a location that
is not the current Offset.