Skip to content

Missing Serialization Support #25

@sumanjeet0012

Description

@sumanjeet0012

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:

  1. Codec base class - Abstract interface for implementing codecs
  2. Built-in codecs - JSONCodec and RawCodec
  3. Generic functions - encode() and decode() with auto-detection
  4. Codec registry - For custom codec registration
  5. Exception types - EncodeError, DecodeError, UnknownCodecError

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions