Data types¶
Messages are encoded and decoded by Term. Its Data types page has the full mapping in both directions and the options of the codec; this page is what a Pyrlang user meets first.
Erlang |
In a Python process |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
native record (OTP 29) |
Things to know:
Strings. An Erlang string is a list of integers. A list of up to 65535 integers that are all below 256 arrives as a Python
str, even when Erlang meant numbers:[1, 2, 3]arrives as'\x01\x02\x03'. Any other list arrives as alist. A Pythonstris sent as an Erlang string. To pass text without surprises, send UTF-8 binaries (<<"text"/utf8>>, Pythonbytes).Noneis sent as the atomundefined, andundefinedarrives asNone.Atoms as dict keys. An
Atomequals thestrof the same text. A map that has both an atom and a string of the same text as keys cannot become adictand is refused; the connection that sent it is closed.Bitstrings arrive as
BitString(Term’s own default is a tuple), so one that is sent back is a bitstring again.A
Processobject inside a message is sent as its pid.Other Python objects are sent as
{ClassName, #{Field => Value}}of their public attributes, or as what their__etf__()method returns.
A message that cannot be decoded is treated as a protocol error: it is logged and the connection to that node is closed, as an Erlang node does.