A simple command/stream multiplexer
Project description
This library packages various codecs used for MoaT protocols in a way that’s reason- and stream-able.
Interface
Codec
encode(obj)
Encode the object to a bytestream.
decode(bytes)
Decode the given bytes to a single object.
feed(bytes, final=False)
Data stream. Returns an array of objects.
This method only exists when a sequence of encoded objects can be streamed, i.e. contains built-in message boundaries.
if @final is True, raise an exception if there is an incomplete object in the buffer after this call.
getstate(), setstate(*args)
A streaming decoder may store partially-decoded state (unprocessed buffer) here.
The list of accepted objects is implementation dependent.
Extension
Extension types vary by whether they carry binary data as in (msgpack), or objects (as in cbor).
binary (classvar): True if msgpack-style, False if cbor-style
encoder(cls, key, fn)
Encode an object obj of type type. fn(codec, obj) must return a bytestring / an encodeable object. If the registration key is None the function must return a tuple with the key as first element.
decoder(key, fn)
Add a decoder (key, data) to an object. fn(codec, data) is called with a bytestring / a decoded object, and returns whatever has been encoded.
Extensions get the codec as their first argument. They can use it to store data, e.g. references. The extension object is available as codec.ext.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file moat_lib_codec-0.2.4.tar.gz
.
File metadata
- Download URL: moat_lib_codec-0.2.4.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebeb745c22974bc7771cf0a44a4a490ee1dd067ad92cc71c56fe83366d3ad193 |
|
MD5 | 1a7a3e40d1d12ea70609a64e40d3dbfe |
|
BLAKE2b-256 | 6c4c89da1cbc9a7f5eeefefc17244aa095e0566fa624191c274dc2513e0102d3 |
File details
Details for the file moat_lib_codec-0.2.4-py3-none-any.whl
.
File metadata
- Download URL: moat_lib_codec-0.2.4-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ab28db4a7193beb7962e8fd6f1d27a916ac4ae1a6a7ccb72cd22058e8f04ca83 |
|
MD5 | 1002e57bdef93883d8fef9c9b8d65485 |
|
BLAKE2b-256 | a39915fac4d3bba2a9dbd3e993224b09aa83303126c439841e2d47d8fe8f934c |