Erlang -- erl_marshal

Erl_Interface

Reference Manual

Version 3.10.3

- User's Guide
- Reference Manual
- Release Notes
- PDF
- Top

- Expand All
- Contract All

### Table of Contents

- ei
  - Top of manual page
  - ei_decode_atom()
  - ei_decode_atom_as()
  - ei_decode_bignum()
  - ei_decode_binary()
  - ei_decode_boolean()
  - ei_decode_char()
  - ei_decode_double()
  - ei_decode_ei_term()
  - ei_decode_fun()
  - ei_decode_list_header()
  - ei_decode_long()
  - ei_decode_longlong()
  - ei_decode_map_header()
  - ei_decode_pid()
  - ei_decode_port()
  - ei_decode_ref()
  - ei_decode_string()
  - ei_decode_term()
  - ei_decode_trace()
  - ei_decode_tuple_header()
  - ei_decode_ulong()
  - ei_decode_ulonglong()
  - ei_decode_version()
  - ei_encode_atom()
  - ei_encode_atom_as()
  - ei_encode_atom_len()
  - ei_encode_atom_len_as()
  - ei_encode_bignum()
  - ei_encode_binary()
  - ei_encode_boolean()
  - ei_encode_char()
  - ei_encode_double()
  - ei_encode_empty_list()
  - ei_encode_fun()
  - ei_encode_list_header()
  - ei_encode_long()
  - ei_encode_longlong()
  - ei_encode_map_header()
  - ei_encode_pid()
  - ei_encode_port()
  - ei_encode_ref()
  - ei_encode_string()
  - ei_encode_string_len()
  - ei_encode_term()
  - ei_encode_trace()
  - ei_encode_tuple_header()
  - ei_encode_ulong()
  - ei_encode_ulonglong()
  - ei_encode_version()
  - ei_get_type()
  - ei_print_term()
  - ei_s_print_term()
  - ei_set_compat_rel()
  - ei_skip_term()
  - ei_x_append()
  - ei_x_append_buf()
  - ei_x_encode_atom()
  - ei_x_encode_atom_as()
  - ei_x_encode_atom_len()
  - ei_x_encode_atom_len_as()
  - ei_x_encode_bignum()
  - ei_x_encode_binary()
  - ei_x_encode_boolean()
  - ei_x_encode_char()
  - ei_x_encode_double()
  - ei_x_encode_empty_list()
  - ei_x_encode_fun()
  - ei_x_encode_list_header()
  - ei_x_encode_long()
  - ei_x_encode_longlong()
  - ei_x_encode_map_header()
  - ei_x_encode_pid()
  - ei_x_encode_port()
  - ei_x_encode_ref()
  - ei_x_encode_string()
  - ei_x_encode_string_len()
  - ei_x_encode_term()
  - ei_x_encode_trace()
  - ei_x_encode_tuple_header()
  - ei_x_encode_ulong()
  - ei_x_encode_ulonglong()
  - ei_x_encode_version()
  - ei_x_format()
  - ei_x_format_wo_ver()
  - ei_x_free()
  - ei_x_new()
  - ei_x_new_with_version()
  - free_fun()
- ei_connect
  - Top of manual page
  - *ei_gethostbyaddr()
  - *ei_gethostbyaddr_r()
  - *ei_gethostbyname()
  - *ei_gethostbyname_r()
  - ei_accept()
  - ei_accept_tmo()
  - ei_connect()
  - ei_connect_init()
  - ei_connect_tmo()
  - ei_connect_xinit()
  - ei_get_tracelevel()
  - ei_publish()
  - ei_publish_tmo()
  - ei_receive()
  - ei_receive_encoded()
  - ei_receive_encoded_tmo()
  - ei_receive_msg()
  - ei_receive_msg_tmo()
  - ei_receive_tmo()
  - ei_reg_send()
  - ei_reg_send_tmo()
  - ei_rpc()
  - ei_rpc_from()
  - ei_rpc_to()
  - ei_self()
  - ei_send()
  - ei_send_encoded()
  - ei_send_encoded_tmo()
  - ei_send_reg_encoded()
  - ei_send_reg_encoded_tmo()
  - ei_send_tmo()
  - ei_set_tracelevel()
  - ei_thisalivename()
  - ei_thishostname()
  - ei_thisnodename()
  - ei_unpublish()
  - ei_unpublish_tmo()
  - ei_xconnect()
  - ei_xconnect_tmo()
  - ei_xreceive_msg()
  - ei_xreceive_msg_tmo()
- registry
  - Top of manual page
  - ei_reg_close()
  - ei_reg_delete()
  - ei_reg_dump()
  - ei_reg_getfval()
  - ei_reg_getival()
  - ei_reg_getpval()
  - ei_reg_getsval()
  - ei_reg_getval()
  - ei_reg_markdirty()
  - ei_reg_open()
  - ei_reg_purge()
  - ei_reg_resize()
  - ei_reg_restore()
  - ei_reg_setfval()
  - ei_reg_setival()
  - ei_reg_setpval()
  - ei_reg_setsval()
  - ei_reg_setval()
  - ei_reg_stat()
  - ei_reg_tabstat()
- erl_connect
  - Top of manual page
  - *erl_gethostbyaddr()
  - *erl_gethostbyaddr_r()
  - *erl_gethostbyname()
  - *erl_gethostbyname_r()
  - erl_accept()
  - erl_close_connection()
  - erl_connect()
  - erl_connect_init()
  - erl_connect_xinit()
  - erl_publish()
  - erl_receive()
  - erl_receive_msg()
  - erl_reg_send()
  - erl_rpc()
  - erl_rpc_from()
  - erl_rpc_to()
  - erl_send()
  - erl_thisalivename()
  - erl_thiscookie()
  - erl_thiscreation()
  - erl_thishostname()
  - erl_thisnodename()
  - erl_unpublish()
  - erl_xconnect()
  - erl_xreceive_msg()
- erl_error
  - Top of manual page
  - erl_err_msg()
  - erl_err_quit()
  - erl_err_ret()
  - erl_err_sys()
  - erl_errno()
- erl_eterm
  - Top of manual page
  - erl_cons()
  - erl_copy_term()
  - erl_element()
  - erl_hd()
  - erl_init()
  - erl_iolist_length()
  - erl_iolist_to_binary()
  - erl_iolist_to_string()
  - erl_length()
  - erl_mk_atom()
  - erl_mk_binary()
  - erl_mk_empty_list()
  - erl_mk_estring()
  - erl_mk_float()
  - erl_mk_int()
  - erl_mk_list()
  - erl_mk_long_ref()
  - erl_mk_pid()
  - erl_mk_port()
  - erl_mk_ref()
  - erl_mk_string()
  - erl_mk_tuple()
  - erl_mk_uint()
  - erl_mk_var()
  - erl_print_term()
  - erl_set_compat_rel()
  - erl_size()
  - erl_tl()
  - erl_var_content()
- erl_format
  - Top of manual page
  - erl_format()
  - erl_match()
- erl_global
  - Top of manual page
  - erl_global_names()
  - erl_global_register()
  - erl_global_unregister()
  - erl_global_whereis()
- erl_malloc
  - Top of manual page
  - erl_alloc_eterm()
  - erl_eterm_release()
  - erl_eterm_statistics()
  - erl_free()
  - erl_free_array()
  - erl_free_compound()
  - erl_free_term()
  - erl_malloc()
- erl_marshal
  - Top of manual page
  - erl_compare_ext()
  - erl_decode()
  - erl_decode_buf()
  - erl_encode()
  - erl_encode_buf()
  - erl_ext_size()
  - erl_ext_type()
  - erl_peek_ext()
  - erl_term_len()
- erl_call

# erl_marshal

### C Library

erl_marshal

### Library Summary

Encoding and decoding of Erlang terms.

### Description

This module contains functions for encoding Erlang terms into a sequence of bytes, and for decoding Erlang terms from a sequence of bytes.

### Exports

int erl_compare_ext(bufp1, bufp2)

### Types

unsigned char *bufp1,*bufp2;

Compares two encoded terms.

- bufp1 is a buffer containing an encoded Erlang term term1.
- bufp2 is a buffer containing an encoded Erlang term term2.

Returns 0 if the terms are equal, -1 if term1 < term2, or 1 if term2 < term1.

ETERM *erl_decode(bufp)
ETERM *erl_decode_buf(bufpp)

### Types

unsigned char *bufp;
unsigned char **bufpp;

erl_decode() and erl_decode_buf() decode the contents of a buffer and return the corresponding Erlang term. erl_decode_buf() provides a simple mechanism for dealing with several encoded terms stored consecutively in the buffer.

- bufp is a pointer to a buffer containing one or more encoded Erlang terms.

- bufpp is the address of a buffer pointer. The buffer contains one or more consecutively encoded Erlang terms. Following a successful call to erl_decode_buf(), bufpp is updated so that it points to the next encoded term.

erl_decode() returns an Erlang term corresponding to the contents of bufp on success, otherwise NULL. erl_decode_buf() returns an Erlang term corresponding to the first of the consecutive terms in bufpp and moves bufpp forward to point to the next term in the buffer. On failure, each of the functions return NULL.

int erl_encode(term, bufp)
int erl_encode_buf(term, bufpp)

### Types

ETERM *term;
unsigned char *bufp;
unsigned char **bufpp;

erl_encode() and erl_encode_buf() encode Erlang terms into external format for storage or transmission. erl_encode_buf() provides a simple mechanism for encoding several terms consecutively in the same buffer.

- term is an Erlang term to be encoded.

- bufp is a pointer to a buffer containing one or more encoded Erlang terms.

- bufpp is a pointer to a pointer to a buffer containing one or more consecutively encoded Erlang terms. Following a successful call to erl_encode_buf(), bufpp is updated so that it points to the position for the next encoded term.

These functions return the number of bytes written to buffer on success, otherwise 0.

Notice that no bounds checking is done on the buffer. It is the caller's responsibility to ensure that the buffer is large enough to hold the encoded terms. You can either use a static buffer that is large enough to hold the terms you expect to need in your program, or use erl_term_len() to determine the exact requirements for a given term.

The following can help you estimate the buffer requirements for a term. Notice that this information is implementation-specific, and can change in future versions. If you are unsure, use erl_term_len().

Erlang terms are encoded with a 1 byte tag that identifies the type of object, a 2- or 4-byte length field, and then the data itself. Specifically:

Tuples
  Need 5 bytes, plus the space for each element.
Lists
  Need 5 bytes, plus the space for each element, and 1 more byte for the empty list at the end.
Strings and atoms
  Need 3 bytes, plus 1 byte for each character (the terminating 0 is not encoded). Really long strings (more than 64k characters) are encoded as lists. Atoms cannot contain more than 256 characters.
Integers
  Need 5 bytes.
Characters
  (Integers < 256) need 2 bytes.
Floating point numbers
  Need 32 bytes.
Pids
  Need 10 bytes, plus the space for the node name, which is an atom.
Ports and Refs
  Need 6 bytes, plus the space for the node name, which is an atom.

The total space required is the result calculated from the information above, plus 1 more byte for a version identifier.

int erl_ext_size(bufp)

### Types

unsigned char *bufp;

Returns the number of elements in an encoded term.

unsigned char erl_ext_type(bufp)

### Types

unsigned char *bufp;

Identifies and returns the type of Erlang term encoded in a buffer. It skips a trailing magic identifier.

Returns 0 if the type cannot be determined or one of:

- ERL_INTEGER
- ERL_ATOM
- ERL_PID (Erlang process identifier)
- ERL_PORT
- ERL_REF (Erlang reference)
- ERL_EMPTY_LIST
- ERL_LIST
- ERL_TUPLE
- ERL_FLOAT
- ERL_BINARY
- ERL_FUNCTION

unsigned char *erl_peek_ext(bufp, pos)

### Types

unsigned char *bufp;
int pos;

This function is used for stepping over one or more encoded terms in a buffer, to directly access later term.

- bufp is a pointer to a buffer containing one or more encoded Erlang terms.
- pos indicates how many terms to step over in the buffer.

Returns a pointer to a subterm that can be used in a later call to erl_decode() to retrieve the term at that position. If there is no term, or pos would exceed the size of the terms in the buffer, NULL is returned.

int erl_term_len(t)

### Types

ETERM *t;

Determines the buffer space that would be needed by t if it were encoded into Erlang external format by erl_encode().

Returns the size in bytes.