bpack.codecs module

Base classes and utility functions for codecs.

class bpack.codecs.BaseCodec(descriptor)[source]

Bases: object

baseunits: bpack.enums.EBaseUnits
property descriptor
class bpack.codecs.BaseStructCodec(descriptor, codec=None, decode_converters=None, encode_converters=None)[source]

Bases: bpack.codecs.Codec

decode(data: bytes)[source]

Decode binary data and return a record object.

encode(record) bytes[source]

Encode a record object into binary data.

baseunits: bpack.enums.EBaseUnits
property format: str

Return the format string.

class bpack.codecs.Codec(descriptor)[source]

Bases: bpack.codecs.Decoder, bpack.codecs.Encoder, abc.ABC

baseunits: bpack.enums.EBaseUnits
class bpack.codecs.ConverterInfo(func, src, dst)[source]

Bases: tuple

property dst

Alias for field number 2

property func

Alias for field number 0

property src

Alias for field number 1

class bpack.codecs.Decoder(descriptor)[source]

Bases: bpack.codecs.BaseCodec, abc.ABC

abstract decode(data: bytes)[source]
baseunits: bpack.enums.EBaseUnits
class bpack.codecs.Encoder(descriptor)[source]

Bases: bpack.codecs.BaseCodec, abc.ABC

abstract encode(record) bytes[source]
baseunits: bpack.enums.EBaseUnits
bpack.codecs.get_codec(descriptor) Union[bpack.codecs.Decoder, bpack.codecs.Encoder, bpack.codecs.Codec][source]

Return the codec instance attached to the input descriptor.

bpack.codecs.get_codec_type(descriptor) Type[Union[bpack.codecs.Decoder, bpack.codecs.Encoder, bpack.codecs.Codec]][source]

Return the type of the codec attached to the input descriptor.

bpack.codecs.has_codec(descriptor, codec_type: Optional[Type[Union[bpack.codecs.Decoder, bpack.codecs.Encoder, bpack.codecs.Codec]]] = None) bool[source]

Return True if the input descriptor has a codec attached.

A descriptor decorated with a codec decorator has an attached codec instance and “frombytes”/”tobytes” methods (depending on the kind of codec).

The codec_type parameter can be used to query for specific codec features:

  • codec_type=None: return True for any king of codec

  • codec_type=:class:Decoder: return True if the attached coded has decoding capabilities

  • codec_type=:class:Encoder: return True if the attached coded has encoding capabilities

  • codec_type=:class:Codec: return True if the attached coded has both encoding and decoding capabilities

bpack.codecs.make_codec_decorator(codec_type: Type[Union[bpack.codecs.Decoder, bpack.codecs.Encoder, bpack.codecs.Codec]])[source]

Generate a codec decorator for the input decoder class.