-
Notifications
You must be signed in to change notification settings - Fork 15
Open
Description
Summary
Add serialization support to py-multicodec with built-in JSON and raw codecs, addressing a key gap identified in the py-multicodec comparison analysis.
Problem
Currently, py-multicodec only provides low-level prefix operations (add_prefix, remove_prefix, etc.). Users must manually serialize/deserialize data before using these functions:
import json
from multicodec import add_prefix, remove_prefix
# Current workflow (manual)
data = {"hello": "world"}
json_bytes = json.dumps(data).encode()
prefixed = add_prefix("json", json_bytes)
# Decoding
raw_bytes = remove_prefix(prefixed)
decoded = json.loads(raw_bytes)Other multicodec implementations (rust-multicodec, js-multiformats) provide integrated serialization.
Proposed Solution
Add a serialization module with:
- Codec base class - Abstract interface for implementing codecs
- Built-in codecs -
JSONCodecandRawCodec - Generic functions -
encode()anddecode()with auto-detection - Codec registry - For custom codec registration
- Exception types -
EncodeError,DecodeError,UnknownCodecError
Related
- Discussion: py-multicodec gap analysis #1063
Metadata
Metadata
Assignees
Labels
No labels