Base64 Encoder Serializer

base64 encoder serializer module.

class easynetwork.serializers.wrapper.base64.Base64EncoderSerializer

Bases: AutoSeparatedPacketSerializer[_T_SentDTOPacket, _T_ReceivedDTOPacket]

A serializer wrapper to handle base64 encoded data, built on top of base64 module.

__init__(serializer: AbstractPacketSerializer[_T_SentDTOPacket, _T_ReceivedDTOPacket], *, alphabet: Literal['standard', 'urlsafe'] = 'urlsafe', checksum: bool | str | bytes = False, separator: bytes = b'\r\n', limit: int = DEFAULT_SERIALIZER_LIMIT, debug: bool = False) None
Parameters:
  • serializer (AbstractPacketSerializer[_T_SentDTOPacket, _T_ReceivedDTOPacket]) – The serializer to wrap.

  • alphabet (Literal['standard', 'urlsafe']) –

    The base64 alphabet to use. Possible values are:

    • "standard": Use standard alphabet.

    • "urlsafe": Use URL- and filesystem-safe alphabet.

    Defaults to "urlsafe".

  • checksum (bool | str | bytes) – If True, appends a sha256 checksum to the serialized data. checksum can also be a URL-safe base64-encoded 32-byte key for a signed checksum.

  • separator (bytes) – Token for AutoSeparatedPacketSerializer. Used in incremental serialization context.

  • limit (int) – Maximum buffer size. Used in incremental serialization context.

  • debug (bool) – If True, add information to DeserializeError via the error_info attribute.

final serialize(packet: _T_SentDTOPacket) bytes

Serializes packet and encodes the result in base64.

Parameters:

packet (_T_SentDTOPacket) – The Python object to serialize.

Returns:

a byte sequence.

Return type:

bytes

final deserialize(data: bytes) _T_ReceivedDTOPacket

Decodes base64 token data and deserializes the result.

Parameters:

data (bytes) – The byte sequence to deserialize.

Raises:
Returns:

the deserialized Python object.

Return type:

_T_ReceivedDTOPacket

classmethod Base64EncoderSerializer.generate_key() bytes

Generates a fresh key suitable for signed checksums.

Keep this some place safe!

Return type:

bytes