Protocol

class laminar.configurations.serde.Protocol

Bases: object

Generic base class for defining ser(de) protocols.

Methods

dump

Serialize a value to a file.

dumps

Serialize a value to a byte string.

hexdigest

Compute the hexdigest to generate the content address.

load

Deserialize a value from a file.

loads

Deserialize a value from a byte stream.

read

Read a value from a URI with a custom protocol.

write

Write a value to a URI with a custom protocol.

Attributes

__init__()
dump(value: Any, file: BinaryIO) None

Serialize a value to a file.

Usage:

with open(..., "wb") as file:
    Protocol().dump(..., file)
Parameters
value: Any

Value to serialize.

file: BinaryIO

File handler to write to.

dumps(value: Any) bytes

Serialize a value to a byte string.

Usage:

Protocol.dumps(...)
Parameters
value: Any

Value to serialize.

Returns

Serialized value.

hexdigest(value: Any) str

Compute the hexdigest to generate the content address.

Parameters
value: Any

Value to compute hexdigest from.

Returns

Hexdigest to use as the content address.

load(file: BinaryIO) Any

Deserialize a value from a file.

Usage:

with open(..., "rb") as file:
    Protocol().load(file)
Parameters
file: BinaryIO

File handler to read from.

Returns

Deserialized value.

loads(stream: bytes) Any

Deserialize a value from a byte stream.

Usage:

Protocol().loads(...)
Parameters
stream: bytes

Bytes to deserialize

Returns

Deserialized value.

read(uri: str) Any

Read a value from a URI with a custom protocol.

Parameters
uri: str

URI to read from.

Returns

Value from the URI.

write(value: Any, uri: str) None

Write a value to a URI with a custom protocol.

Parameters
value: Any

Value to write to the URI.

uri: str

URI to write to.