The MoaT-Codec library
% start synopsis % start main
This library packages various codecs used for MoaT protocols in a way that's reason- and stream-able.
% end synopsis
Supplied codecs
- CBOR
- msgpack
- no-op
- UTF-8
- JSON
- YAML
On CPython the CBOR codec is implemented in pure Python. MicroPython
uses the ccbor C module
instead (compiled into the firmware; moat micro prep builds it into the
test interpreters). The wire format is identical; the C decoder is stricter
than the pure-Python one in a few places:
- duplicate map keys are an error instead of silently overwriting the earlier value,
- unassigned CBOR simple values are an error instead of a
Tag, - half/single-precision floats decode to their exact value instead of being rounded to a fixed number of significant digits,
- the nesting depth is limited (default 32),
- a not-well-formed byte in an incremental stream is skipped after the error is reported, so decoding can resynchronise.
% end main
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
objof typetype.fn(codec, obj)must return a bytestring / an encodeable object. If the registration key isNonethe 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.
Metadata
Release files for moat-lib-codec 0.4.23
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| moat_lib_codec-0.4.23.tar.gz | 23.4 kB | Without provenance | Details for moat_lib_codec-0.4.23.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| moat_lib_codec-0.4.23-py3-none-any.whl | Python 3 | none | any | Details for moat_lib_codec-0.4.23-py3-none-any.whl |
Total release size: 50.0 kB
Release files / moat_lib_codec-0.4.23.tar.gz
| Download URL | moat_lib_codec-0.4.23.tar.gz |
|---|---|
| Size | 23.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b33e8517428cd3992acaf765e392b9f588e75e8cf7b045dc5de52528542267ca
|
|
BLAKE2b-256 checksum How to use checksums |
0c419a246fca02841851a22c423ce341dd81d25d2e55e95bc901f2c34a74a881
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Release files / moat_lib_codec-0.4.23-py3-none-any.whl
| Download URL | moat_lib_codec-0.4.23-py3-none-any.whl |
|---|---|
| Size | 26.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
127bfb8edf3187864073d93da4a7a598c53d4b7e74bb32a0c151f1c6e3230710
|
|
BLAKE2b-256 checksum How to use checksums |
191dcd54451bfcc15724f9be8ef7a45a3011f20787d11609bb0410cde55876a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Security for moat-lib-codec 0.4.23
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.