aiomas.codecs — aiomas 0.2.0 documentation

# `aiomas.codecs`

This package imports the codecs that can be used for de- and encoding incoming and outgoing messages:

- `JSON` uses JSON
- `MsgPack` uses msgpack

All codecs should implement the base class `Codec`.

class `aiomas.codecs.` `Codec`

  Base class for all Codecs.

  Subclasses must implement `encode()` and `decode()`.

  `encode`(data)

    Encode the given data and return a `bytes` object.

  `decode`(data)

    Decode data from `bytes` to the original data structure.

  `add_serializer`(type, serialize, deserialize)

    Add methods to serialize and deserialize objects typed type.

    This can be used to de-/encode objects that the codec otherwise couldn’t encode.

    serialize will receive the unencoded object and needs to return an encodable serialization of it.

    deserialize will receive an objects representation and should return an instance of the original object.

  `serialize_obj`(obj)

    Serialize obj to something that the codec can encode.

  `deserialize_obj`(obj_repr)

    Deserialize the original object from obj_repr.

class `aiomas.codecs.` `JSON`

  A `Codec` that uses JSON to encode and decode messages.

class `aiomas.codecs.` `MsgPack`

  A `Codec` that uses msgpack to encode and decode messages.