term.py_codec_impl¶
Module implements encoder and decoder from ETF (Erlang External Term Format) used by the network distribution layer.
- term.py_codec_impl.binary_to_term(data, options=None)¶
Strip 131 header and unpack if the data was compressed.
- Parameters:
data (bytes) – The incoming encoded data with the 131 byte
options (dict[str, Any] | None) – as for
binary_to_term_2()
- Raises:
PyCodecError – when the tag is not 131, when compressed data is incomplete or corrupted, on any malformed input, and when an option callable raises (the original is its
__cause__)- Returns:
The value and the remaining unconsumed bytes
- Return type:
tuple[str | List[Any] | tuple | dict | int | float | bytes | BaseTerm | None, bytes]
- term.py_codec_impl.binary_to_term_2(data, options=None)¶
Decode one term that has no version byte 131.
- Parameters:
data (bytes) – the encoded term; more bytes may follow it
options (dict[str, Any] | None) – the decode options described in
term.codec
- Raises:
PyCodecError – on malformed input, and when an option callable raises (the original exception is its
__cause__)- Returns:
the value, and the bytes that follow the term
- Return type:
tuple[str | List[Any] | tuple | dict | int | float | bytes | BaseTerm | None, bytes]
- term.py_codec_impl.term_to_binary(val, opt=None)¶
Encode a value, starting with the version byte 131.
- Parameters:
val (Any) – the value to encode
opt (dict[str, Any] | None) – the encode options described in
term.codec
- Raises:
- Returns:
the encoded term
- Return type:
- term.py_codec_impl.term_to_binary_2(val, encode_hook, max_depth=4096)¶
Encode a value without the 131 header byte.
- Parameters:
- Returns:
the encoded term
- Raises:
PyCodecError – for a value nested deeper than
max_depth, a value that contains itself, and a value with no encoding- Return type:
- exception term.py_codec_impl.PyCodecError¶
Bases:
ExceptionA term could not be decoded or a value could not be encoded.
- term.py_codec_impl.generic_serialize_object(obj, cycle_detect=None)¶
The stand-in for an object that has no encoding of its own: the tuple
(ClassName, Fields)of its class name and public attributes.