Changeset View
Changeset View
Standalone View
Standalone View
swh/core/api/serializers.py
Show First 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | def encode_types(obj): | ||||
b'd': encoder(obj), | b'd': encoder(obj), | ||||
} | } | ||||
return obj | return obj | ||||
return msgpack.packb(data, use_bin_type=True, default=encode_types) | return msgpack.packb(data, use_bin_type=True, default=encode_types) | ||||
def msgpack_loads(data: bytes, extra_decoders=None) -> Any: | def msgpack_loads(data: bytes, extra_decoders=None) -> Any: | ||||
"""Read data as a msgpack stream""" | """Read data as a msgpack stream. | ||||
.. Caution:: | |||||
This function is used by swh.journal to decode the contents of the | |||||
journal. This function **must** be kept backwards-compatible. | |||||
""" | |||||
decoders = DECODERS | decoders = DECODERS | ||||
if extra_decoders: | if extra_decoders: | ||||
decoders = {**decoders, **extra_decoders} | decoders = {**decoders, **extra_decoders} | ||||
def decode_types(obj): | def decode_types(obj): | ||||
# Support for current encodings | # Support for current encodings | ||||
if set(obj.keys()) == {b'd', b'swhtype'}: | if set(obj.keys()) == {b'd', b'swhtype'}: | ||||
decoder = decoders.get(obj[b'swhtype']) | decoder = decoders.get(obj[b'swhtype']) | ||||
Show All 39 Lines |