heros.serdes¶
Attributes¶
Classes¶
An object store to be used to keep week references to objects identified by a serializable identifier (int64). |
|
Functions¶
|
Handle custom types in serialization. |
|
Decode the custom CBOR tags used by HEROS (cbor2 >=6 version). |
|
|
|
The CBOR header that cbor2 writes for a byte string of the given length. |
|
Replace the placeholder sentinels in serialized data with the raw ndarray buffers. |
|
|
|
Deserialize a CBOR byte string. |
Module Contents¶
- heros.serdes.ndarray_tag = 4242¶
- heros.serdes.hero_tag = 9000¶
- heros.serdes.unserializable_tag = 9001¶
- heros.serdes.unserializable_object_reference_tag = 9002¶
- heros.serdes.hero_event_tag = 9003¶
- heros.serdes.hero_method_tag = 9004¶
- heros.serdes.hero_exception_tag = 9005¶
- heros.serdes.cborv6¶
- class heros.serdes.ObjectStore[source]¶
An object store to be used to keep week references to objects identified by a serializable identifier (int64).
- _cache¶
- add(object: ObjectStore.add.object) int[source]¶
Add object to store and return it’s identifier
- Parameters:
object – object to store
- Returns:
Identifier to retrieve the object from the store again
- get(identifier: int) object[source]¶
Retrieve an object identified by :param:identifier from the store. If the object does not exist any more, None is returned.
- Parameters:
identifier – the identifier obtained when storing the object
- Returns:
object corresponding to the identifier or None if the object does not exist any more
- heros.serdes.obj_store¶
- class heros.serdes.UnserializableRemoteObject(type: str, id: int, representation: str)[source]¶
- type¶
- representation¶
- id¶
- heros.serdes.cbor_default_encoder(encoder, value, patches=None)[source]¶
Handle custom types in serialization.
- Parameters:
encoder – the CBOR encoder
value – the value to encode
patches – list that collects (32 byte placeholder, ndarray) pairs for the ndarrays encoded in this run. Only used with cbor2 >= 6, see
serialize().
- heros.serdes.cbor_tag_hook(tag, _immutable, *, make_remote: collections.abc.Callable[..., Any] | None = None)[source]¶
Decode the custom CBOR tags used by HEROS (cbor2 >=6 version).
- Parameters:
tag – the tagged value to decode
make_remote – factory called as
make_remote(name, realm=realm)to build a HERO from a HERO tag. Defaults toheros.RemoteHERO.
- Returns:
The decoded object, or the unchanged tag if it is not a HEROS tag.
- heros.serdes.decode_tag(tag, make_remote: collections.abc.Callable[..., Any] | None = None)[source]¶
- heros.serdes._bytes_header(nbytes)[source]¶
The CBOR header that cbor2 writes for a byte string of the given length.
- heros.serdes._splice_ndarray_data(data, patches)[source]¶
Replace the placeholder sentinels in serialized data with the raw ndarray buffers.
- Parameters:
data – the serialized byte string containing placeholders
patches – list of (placeholder, ndarray) pairs collected during encoding
- heros.serdes.deserialize(bytes, *, make_remote: collections.abc.Callable[..., Any] | None = None)[source]¶
Deserialize a CBOR byte string.
- Parameters:
bytes – the byte string to deserialize
make_remote – factory used to build HEROs, see
cbor_tag_hook(). Defaults toheros.RemoteHERO.
- Returns:
The deserialized object.