Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

moat_lib_codec-0.3.0.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

moat_lib_codec-0.3.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file moat_lib_codec-0.3.0.tar.gz.

File metadata

  • Download URL: moat_lib_codec-0.3.0.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for moat_lib_codec-0.3.0.tar.gz
Algorithm Hash digest
SHA256 75f814ba95ca84ef00b264891ee5f78e24fe196a7ef4dc785d24a9b88dc4826f
MD5 cbf4c1e6b0ff570003c5161db009e626
BLAKE2b-256 dfb0ff7a678ae2de1b253fb319d1f08f4c60e75343e6eb1c9099870b6f3c582b

See more details on using hashes here.

File details

Details for the file moat_lib_codec-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for moat_lib_codec-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6ddab687bb47fbf50e2545580ae07c430b76a266b3bfd0e2b236a0218efc1769
MD5 ae356b4c421148970e3a4845fa589c3f
BLAKE2b-256 40dfa4616e3ee5f33e8950c34742f37fa52b3665801b40c34710ded30fab352d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page