externalterm.h
Include dependency graph for externalterm.h:
This graph shows which files directly or indirectly include externalterm.h:
External term deserialization functions.
This header provides external term deserialization functions.
Defines
-
EXTERNAL_TERM_TAG 131
Enums
Functions
-
term externalterm_from_binary(Context *ctx, term binary, size_t *bytes_read)
Create a term from a binary.
Deserialize a binary term that stores term data in Erlang external term format, and instantiate the serialized terms. The heap from the context will be used to allocate the instantiated terms. This function is the complement of externalterm_to_binary. WARNING: This function may call the GC, which may render the input binary invalid. See externalterm_from_binary_with_roots
- Parameters:
ctx – the context that owns the memory that will be allocated.
dst – a pointer to a term that will contain the binary encoded term.
binary – the binary.
bytes_read – the number of bytes read from the input binary.
- Returns:
the term deserialized from the input term, or an invalid term, if deserialization fails.
-
term externalterm_from_binary_with_roots(Context *ctx, size_t binary_ix, size_t offset, size_t *bytes_read, size_t num_roots, term *roots)
Create a term from a binary.
Deserialize a binary term that stores term data in Erlang external term format, and instantiate the serialized terms. The heap from the context will be used to allocate the instantiated terms. This function is the complement of externalterm_to_binary. WARNING: This function may call the GC, which may render the input binary invalid.
- Parameters:
ctx – the context that owns the memory that will be allocated.
binary_ix – offset of the binary in roots
offset – offset in the binary
bytes_read – the number of bytes read from the input binary.
num_roots – number of roots to preserve in case of GC
roots – roots to preserve in case of GC
- Returns:
the term deserialized from the input term, or an invalid term, if deserialization fails.
-
term externalterm_from_const_literal(const void *external_term, size_t size, Context *ctx)
Gets a term from a const literal (module in flash).
Deserialize an external term from external format and returns a term. Use a heap fragment to store the generated terms. The heap fragment is appended to the context heap. Atoms and binaries are not copied.
- Parameters:
external_term – the const literal buffer that will be deserialized
size – to allocate for term.
ctx – the context that owns the memory that will be allocated.
- Returns:
a term.
-
term externalterm_to_binary(Context *ctx, term t)
Create a binary from a term.
Serialize a term in Erlang external term format, and store the result in a binary term. The heap from the context will be used to allocate the hydrated terms. This function is the complement of externalterm_to_binary. WARNING: This function may call the GC, which may render the input binary invalid.
- Parameters:
ctx – the context that owns the memory that will be allocated.
t – the term to return as binary.
- Returns:
the term deserialized from the input term, or an invalid term, if deserialization fails.
-
enum ExternalTermResult externalterm_compute_external_size_raw(term t, size_t *size, GlobalContext *glb)
Computes the size required for a external term (tag excluded)
This function should be called in order to calculate the required buffer size to store a serialized term in external term format. This function doesn’t prepend the external term 1 byte tag.
- Parameters:
t – the term for which size is calculated
size – the required buffer size (tag excluded)
glb – the global context
- Returns:
EXTERNAL_TERM_OK in case of success
-
enum ExternalTermResult externalterm_serialize_term_raw(void *buf, term t, GlobalContext *glb)
Serialize a term (tag excluded)
This function serializes in external term format given term, and writes it to the given buffer. This function doesn’t prepend the external term 1 byte tag.
- Parameters:
buf – the buffer where the external term is written
t – the term that will be serialized
glb – the global context
- Returns:
EXTERNAL_TERM_OK in case of success
-
static inline enum ExternalTermResult externalterm_compute_external_size(term t, size_t *size, GlobalContext *glb)
Computes the size required for a external term.
This function should be called in order to calculate the required buffer size to store a serialized term in external term format.
- Parameters:
t – the term for which size is calculated
size – the required buffer size (tag excluded)
glb – the global context
- Returns:
EXTERNAL_TERM_OK in case of success
-
static inline enum ExternalTermResult externalterm_serialize_term(void *buf, term t, GlobalContext *glb)
Serialize a term.
This function serializes in external term format given term, and writes it to the given buffer.
- Parameters:
buf – the buffer where the external term is written
t – the term that will be serialized
glb – the global context
- Returns:
EXTERNAL_TERM_OK in case of success