The library
With
It also handles C-nodes, C-programs that talks erlang
distribution with erlang nodes (or other C-nodes) using the
erlang distribution format. The difference between
The decode and encode functions use a buffer an index into the buffer, which points at the point where to encode and decode. The index is updated to point right after the term encoded/decoded. No checking is done whether the term fits in the buffer or not. If encoding goes outside the buffer, the program may crash.
All functions takes two parameter,
The encode functions all assumes that the
There are also encode-functions that uses a dynamic buffer. It
is often more convenient to use these to encode data. All encode
functions comes in two versions: those starting with
All functions return
Some of the decode-functions needs a preallocated buffer. This
buffer must be allocated big enough, and for non compound types
the
By default, the
A call to
If this function is called, it may only be called once
and must be called before any other functions in the
You may run into trouble if this feature is used carelessly. Always make sure that all communicating components are either from the same Erlang/OTP release, or from release X and release Y where all components from release Y are in compatibility mode of release X.
Encodes a version magic number for the binary format. Must be the first token in a binary term.
Encodes a long integer in the binary format. Note that if the code is 64 bits the function ei_encode_long() is exactly the same as ei_encode_longlong().
Encodes an unsigned long integer in the binary format. Note that if the code is 64 bits the function ei_encode_ulong() is exactly the same as ei_encode_ulonglong().
Encodes a GCC
Encodes a GCC
Encodes a GMP
Encodes a double-precision (64 bit) floating point number in the binary format.
Encodes a boolean value, as the atom
Encodes a char (8-bit) as an integer between 0-255 in the binary format.
Note that for historical reasons the integer argument is of
type
Encodes a string in the binary format. (A string in erlang
is a list, but is encoded as a character array in the binary
format.) The string should be zero-terminated, except for
the
Encodes an atom in the binary format. The
Encodes a binary in the binary format. The data is at
Encodes an erlang process identifier, pid, in the binary
format. The
Encodes a fun in the binary format. The
Encodes an erlang port in the binary format. The
Encodes an erlang reference in the binary format. The
This function encodes an
This function encodes an erlang trace token in the binary
format. The
This function encodes a tuple header, with a specified
arity. The next
E.g. to encode the tuple
ei_encode_tuple_header(buf, &i, 2); ei_encode_atom(buf, &i, "a"); ei_encode_tuple_header(buf, &i, 2); ei_encode_atom(buf, &i, "b"); ei_encode_tuple_header(buf, &i, 0);
This function encodes a list header, with a specified
arity. The next
E.g. to encode the list
ei_encode_list_header(buf, &i, 3); ei_encode_atom(buf, &i, "c"); ei_encode_atom(buf, &i, "d"); ei_encode_list_header(buf, &i, 1); ei_encode_atom(buf, &i, "e"); ei_encode_atom(buf, &i, "f"); ei_encode_empty_list(buf, &i);
It may seem that there is no way to create a list without
knowing the number of elements in advance. But indeed
there is a way. Note that the list
To encode a list, without knowing the arity in advance:
while (something()) { ei_x_encode_list_header(&x, 1); ei_x_encode_ulong(&x, i); /* just an example */ } ei_x_encode_empty_list(&x);
This function encodes an empty list. It's often used at the tail of a list.
This function returns the type in
This function decodes the version magic number for the erlang binary term format. It must be the first token in a binary term.
This function decodes a long integer from the binary format. Note that if the code is 64 bits the function ei_decode_long() is exactly the same as ei_decode_longlong().
This function decodes an unsigned long integer from the binary format. Note that if the code is 64 bits the function ei_decode_ulong() is exactly the same as ei_decode_ulonglong().
This function decodes a GCC
This function decodes a GCC
This function decodes an integer in the binary format to a GMP
This function decodes an double-precision (64 bit) floating point number from the binary format.
This function decodes a boolean value from the binary
format. A boolean is actually an atom,
This function decodes a char (8-bit) integer between 0-255
from the binary format.
Note that for historical reasons the returned integer is of
type
This function decodes a string from the binary format. A
string in erlang is a list of integers between 0 and
255. Note that since the string is just a list, sometimes
lists are encoded as strings by
The string is copied to
This function decodes an atom from the binary format. The
name of the atom is placed at
This function decodes a binary from the binary format. The
This function decodes a fun from the binary format. The
Decodes a pid, process identifier, from the binary format.
This function decodes a port identifier from the binary format.
This function decodes a reference from the binary format.
Decodes an erlang trace token from the binary format.
This function decodes a tuple header, the number of elements
is returned in
This function decodes a list header from the binary
format. The number of elements is returned in
Note that lists are encoded as strings, if they consist
entirely of integers in the range 0..255. This function will
not decode such strings, use
This function decodes any term, or at least tries to. If the
term pointed at by
The function returns 0 on successful decoding, -1 on error,
and 1 if the term seems alright, but does not fit in the
The
This function decodes a term from the binary format. The
term is return in
Note that this function is located in the erl_interface library.
This function prints a term, in clear text, to the file
given by
In
The return value is the number of characters written to the
file or string, or -1 if
The argument
Format a term, given as a string, to a buffer. This
functions works like a sprintf for erlang terms. The
~a - an atom, char* ~c - a character, char ~s - a string, char* ~i - an integer, int ~l - a long integer, long int ~u - a unsigned long integer, unsigned long int ~f - a float, float ~d - a double float, double float ~p - an Erlang PID, erlang_pid*
For instance, to encode a tuple with some stuff:
ei_x_format("{~a,~i,~d}", "numbers", 12, 3.14159) encodes the tuple {numbers,12,3.14159}
The
This function allocates a new
This function frees an
These functions appends data at the end of the buffer
This function skips a term in the given buffer, it recursively skips elements of lists and tuples, so that a full term is skipped. This is a way to get the size of an erlang term.
This can be useful when you want to hold arbitrary terms: just skip them and copy the binary term data to some buffer.
The function returns
Some tips on what to check when the emulator doesn't seem to receive the terms that you send.
erl_interface(3)