zlmdb.flatbuffers.flexbuffers

Implementation of FlexBuffers binary format.

For more info check https://google.github.io/flatbuffers/flexbuffers.html and corresponding C++ implementation at https://github.com/google/flatbuffers/blob/master/include/flatbuffers/flexbuffers.h

Classes

Builder

Helper class to encode structural data into flexbuffers format.

Type

Supported types of encoded data.

Functions

Dumps(obj)

Returns bytearray with the encoded python object.

GetRoot(buf)

Returns root Ref object for the given buffer.

Loads(buf)

Returns python object decoded from the buffer.

Module Contents

class Builder(share_strings=False, share_keys=True, force_min_bit_width=BitWidth.W8)[source]

Helper class to encode structural data into flexbuffers format.

Add(value)[source]

Encodes value of any supported type.

Adder(type_)[source]
Blob(value)[source]

Encodes binary blob value.

Parameters:

value – A byte/bytearray value to encode

Returns:

Offset of the encoded value in underlying the byte buffer.

Bool(value)[source]

Encodes boolean value.

Parameters:

value – A boolean value.

Clear()[source]
Finish()[source]

Finishes encoding process and returns underlying buffer.

FixedTypedVectorFromElements(elements, element_type=None, byte_width=0)[source]

Encodes sequence of elements of the same type as fixed typed vector.

Parameters:
  • elements – Sequence of elements, they must be of the same type. Allowed types are Type.INT, Type.UINT, Type.FLOAT. Allowed number of elements are 2, 3, or 4.

  • element_type – Suggested element type. Setting it to None means determining correct value automatically based on the given elements.

  • byte_width – Number of bytes to use per element. For Type.INT and Type.UINT: 1, 2, 4, or 8. For Type.FLOAT: 4 or 8. Setting it to 0 means determining correct value automatically based on the given elements.

Float(value, byte_width=0)[source]

Encodes floating point value.

Parameters:
  • value – A floating point value.

  • byte_width – Number of bytes to use: 4 or 8.

IndirectFloat(value, byte_width=0)[source]

Encodes floating point value indirectly.

Parameters:
  • value – A floating point value.

  • byte_width – Number of bytes to use: 4 or 8.

IndirectInt(value, byte_width=0)[source]

Encodes signed integer value indirectly.

Parameters:
  • value – A signed integer value.

  • byte_width – Number of bytes to use: 1, 2, 4, or 8.

IndirectUInt(value, byte_width=0)[source]

Encodes unsigned integer value indirectly.

Parameters:
  • value – An unsigned integer value.

  • byte_width – Number of bytes to use: 1, 2, 4, or 8.

Int(value, byte_width=0)[source]

Encodes signed integer value.

Parameters:
  • value – A signed integer value.

  • byte_width – Number of bytes to use: 1, 2, 4, or 8.

Key(value)[source]

Encodes key value.

Parameters:

value – A byte/bytearray/str value to encode. Byte object must not contain zero bytes. String object must be convertible to ASCII.

Returns:

Offset of the encoded value in the underlying byte buffer.

property KeyPool[source]
property LastValue[source]
Map(key=None)[source]
MapFromElements(elements)[source]
Null(key=None)[source]

Encodes None value.

ReuseValue(value)[source]
String(value)[source]

Encodes string value.

property StringPool[source]
TypedVector(key=None)[source]
TypedVectorFromElements(elements, element_type=None)[source]

Encodes sequence of elements of the same type as typed vector.

Parameters:
  • elements – Sequence of elements, they must be of the same type.

  • element_type – Suggested element type. Setting it to None means determining correct value automatically based on the given elements.

UInt(value, byte_width=0)[source]

Encodes unsigned integer value.

Parameters:
  • value – An unsigned integer value.

  • byte_width – Number of bytes to use: 1, 2, 4, or 8.

Vector(key=None)[source]
VectorFromElements(elements)[source]

Encodes sequence of any elements as a vector.

Parameters:

elements – sequence of elements, they may have different types.

_Align(alignment)[source]
_CreateVector(elements, typed, fixed, keys=None)[source]

Writes vector elements to the underlying buffer.

_EndMap(start)[source]

Finishes map construction by encodung its elements.

_EndVector(start, typed, fixed)[source]

Finishes vector construction by encodung its elements.

_PushIndirect(value, type_, bit_width)[source]
_ReadKey(offset)[source]
_StartMap()[source]

Starts map construction.

_StartVector()[source]

Starts vector construction.

_Write(fmt, value, byte_width)[source]
_WriteAny(value, byte_width)[source]
_WriteBlob(data, append_zero, type_)[source]
_WriteOffset(offset, byte_width)[source]
_WriteScalarVector(element_type, byte_width, elements, fixed)[source]

Writes scalar vector elements to the underlying buffer.

_WriteVector(fmt, values, byte_width)[source]
__len__()[source]
_buf[source]
_finished = False[source]
_force_min_bit_width[source]
_key_pool[source]
_share_keys = True[source]
_share_strings = False[source]
_stack = [][source]
_string_pool[source]
Dumps(obj)[source]

Returns bytearray with the encoded python object.

GetRoot(buf)[source]

Returns root Ref object for the given buffer.

Loads(buf)[source]

Returns python object decoded from the buffer.

class Type[source]

Bases: enum.IntEnum

Supported types of encoded data.

These are used as the upper 6 bits of a type field to indicate the actual type.

BLOB = 25[source]
BOOL = 26[source]
FLOAT = 3[source]
INDIRECT_FLOAT = 8[source]
INDIRECT_INT = 6[source]
INDIRECT_UINT = 7[source]
INT = 1[source]
static IsFixedTypedVector(type_)[source]
static IsFixedTypedVectorElementType(type_)[source]
static IsInline(type_)[source]
static IsTypedVector(type_)[source]
static IsTypedVectorElementType(type_)[source]
KEY = 4[source]
MAP = 9[source]
NULL = 0[source]
static Pack(type_, bit_width)[source]
STRING = 5[source]
static ToFixedTypedVectorElementType(type_)[source]
static ToTypedVector(element_type, fixed_len=0)[source]

Converts element type to corresponding vector type.

Parameters:
  • element_type – vector element type

  • fixed_len – number of elements: 0 for typed vector; 2, 3, or 4 for fixed typed vector.

Returns:

Typed vector type or fixed typed vector type.

static ToTypedVectorElementType(type_)[source]
UINT = 2[source]
static Unpack(packed_type)[source]
VECTOR = 10[source]
VECTOR_BOOL = 36[source]
VECTOR_FLOAT = 13[source]
VECTOR_FLOAT2 = 18[source]
VECTOR_FLOAT3 = 21[source]
VECTOR_FLOAT4 = 24[source]
VECTOR_INT = 11[source]
VECTOR_INT2 = 16[source]
VECTOR_INT3 = 19[source]
VECTOR_INT4 = 22[source]
VECTOR_KEY = 14[source]
VECTOR_STRING_DEPRECATED = 15[source]
VECTOR_UINT = 12[source]
VECTOR_UINT2 = 17[source]
VECTOR_UINT3 = 20[source]
VECTOR_UINT4 = 23[source]