bpack.codecs module

Base classes and utility functions for codecs.

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

Bases: Decoder, Encoder, ABC

Base class for codecs.

baseunits: EBaseUnits
class bpack.codecs.Decoder(descriptor)[source]

Bases: BaseCodec, ABC

Base class for decoders.

abstract decode(data: bytes)[source]

Decode binary data and return Python object.

baseunits: EBaseUnits
class bpack.codecs.Encoder(descriptor)[source]

Bases: BaseCodec, ABC

Base class for encoders.

abstract encode(record) bytes[source]

Encode python objects into binary data.

baseunits: EBaseUnits
bpack.codecs.has_codec(descriptor, codec_type: Optional[Type[Union[Decoder, Encoder, 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