os_stat_result_serializer.py
ofrak.service.serialization.serializers.os_stat_result_serializer
OsStatResultSerializer (SerializerInterface)
Serialize and deserialize os.stat_result
into PJSONType
.
os.stat_result
is basically a wrapper around a tuple of ints, so we can serialize it as that tuple.
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/os_stat_result_serializer.py
def obj_to_pjson(self, obj: os.stat_result, type_hint: Any) -> PJSONType:
return self._service.to_pjson(obj, Tuple[int, ...])
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/os_stat_result_serializer.py
def pjson_to_obj(self, pjson_obj: PJSONType, type_hint: Any) -> os.stat_result:
return os.stat_result(pjson_obj) # type: ignore