Skip to content

bytes_serializer.py

ofrak.service.serialization.serializers.bytes_serializer

BytesSerializer (SerializerInterface)

Serialize and deserialize bytes into PJSONType.

Implementation: hex string.

obj_to_pjson(self, obj, _type_hint)

Serialize the object to PJSON. Note that the generic self._service.to_pjson can be used here.

Source code in ofrak/service/serialization/serializers/bytes_serializer.py
def obj_to_pjson(self, obj: bytes, _type_hint: Any) -> str:
    return obj.hex()

pjson_to_obj(self, pjson_obj, _type_hint)

Deserialize PJSON into the object. Note that the generic self._service.from_pjson can be used here.

Source code in ofrak/service/serialization/serializers/bytes_serializer.py
def pjson_to_obj(self, pjson_obj: str, _type_hint: Any) -> bytes:
    return bytes.fromhex(pjson_obj)