Skip to content

Commit 49dec34

Browse files
committed
Implemented serization methods in py-multicodec
1 parent d1cd957 commit 49dec34

File tree

5 files changed

+875
-2
lines changed

5 files changed

+875
-2
lines changed

multicodec/__init__.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,68 @@
1313
known_codes,
1414
)
1515

16+
# Exceptions
17+
from .exceptions import (
18+
CodecError,
19+
DecodeError,
20+
EncodeError,
21+
MulticodecError,
22+
UnknownCodecError,
23+
)
24+
1625
# Original multicodec functions
1726
from .multicodec import add_prefix, extract_prefix, get_codec, get_prefix, is_codec, remove_prefix
1827

28+
# Serialization support
29+
from .serialization import (
30+
Codec,
31+
JSONCodec,
32+
RawCodec,
33+
decode,
34+
encode,
35+
get_registered_codec,
36+
is_codec_registered,
37+
json_codec,
38+
list_registered_codecs,
39+
raw_codec,
40+
register_codec,
41+
unregister_codec,
42+
)
43+
1944
__all__ = [
20-
"RESERVED_END",
2145
# Constants
46+
"RESERVED_END",
2247
"RESERVED_START",
2348
# Code type
2449
"Code",
50+
# Serialization base classes
51+
"Codec",
52+
"CodecError",
53+
"DecodeError",
54+
"EncodeError",
55+
# Built-in codecs
56+
"JSONCodec",
57+
# Exceptions
58+
"MulticodecError",
59+
"RawCodec",
60+
"UnknownCodecError",
2561
# Original functions
2662
"add_prefix",
63+
"decode",
64+
# Serialization functions
65+
"encode",
2766
"extract_prefix",
2867
"get_codec",
2968
"get_prefix",
69+
"get_registered_codec",
3070
"is_codec",
71+
"is_codec_registered",
3172
"is_reserved",
32-
# Functions
73+
"json_codec",
3374
"known_codes",
75+
"list_registered_codecs",
76+
"raw_codec",
77+
"register_codec",
3478
"remove_prefix",
79+
"unregister_codec",
3580
]

multicodec/exceptions.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
"""
2+
Exception classes for multicodec.
3+
4+
This module defines the exception hierarchy for multicodec operations,
5+
providing specific error types for different failure modes.
6+
"""
7+
8+
9+
class MulticodecError(Exception):
10+
"""Base exception for all multicodec-related errors."""
11+
12+
pass
13+
14+
15+
class CodecError(MulticodecError):
16+
"""Base exception for codec-related errors."""
17+
18+
pass
19+
20+
21+
class EncodeError(CodecError):
22+
"""Raised when encoding fails."""
23+
24+
pass
25+
26+
27+
class DecodeError(CodecError):
28+
"""Raised when decoding fails."""
29+
30+
pass
31+
32+
33+
class UnknownCodecError(CodecError):
34+
"""Raised when an unknown codec is requested."""
35+
36+
pass
37+
38+
39+
__all__ = [
40+
"CodecError",
41+
"DecodeError",
42+
"EncodeError",
43+
"MulticodecError",
44+
"UnknownCodecError",
45+
]

0 commit comments

Comments
 (0)