bitstring.h

Include dependency graph for bitstring.h:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "3" [label="stdbool.h" tooltip="stdbool.h"]
    "16" [label="refc_binary.h" tooltip="refc_binary.h"]
    "11" [label="assert.h" tooltip="assert.h"]
    "14" [label="utils.h" tooltip="utils.h"]
    "17" [label="list.h" tooltip="list.h"]
    "4" [label="stdint.h" tooltip="stdint.h"]
    "6" [label="stdlib.h" tooltip="stdlib.h"]
    "8" [label="memory.h" tooltip="memory.h"]
    "18" [label="resources.h" tooltip="resources.h"]
    "2" [label="term.h" tooltip="term.h"]
    "15" [label="stddef.h" tooltip="stddef.h"]
    "9" [label="erl_nif.h" tooltip="erl_nif.h"]
    "12" [label="limits.h" tooltip="limits.h"]
    "7" [label="string.h" tooltip="string.h"]
    "10" [label="term_typedef.h" tooltip="term_typedef.h"]
    "1" [label="/__w/AtomVM/AtomVM/src/libAtomVM/bitstring.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/bitstring.h" fillcolor="#BFBFBF"]
    "5" [label="stdio.h" tooltip="stdio.h"]
    "13" [label="inttypes.h" tooltip="inttypes.h"]
    "16" -> "3" [dir=forward tooltip="include"]
    "16" -> "6" [dir=forward tooltip="include"]
    "16" -> "17" [dir=forward tooltip="include"]
    "16" -> "18" [dir=forward tooltip="include"]
    "14" -> "15" [dir=forward tooltip="include"]
    "14" -> "5" [dir=forward tooltip="include"]
    "14" -> "6" [dir=forward tooltip="include"]
    "8" -> "4" [dir=forward tooltip="include"]
    "8" -> "6" [dir=forward tooltip="include"]
    "8" -> "9" [dir=forward tooltip="include"]
    "8" -> "10" [dir=forward tooltip="include"]
    "8" -> "14" [dir=forward tooltip="include"]
    "18" -> "6" [dir=forward tooltip="include"]
    "18" -> "9" [dir=forward tooltip="include"]
    "18" -> "17" [dir=forward tooltip="include"]
    "18" -> "8" [dir=forward tooltip="include"]
    "2" -> "3" [dir=forward tooltip="include"]
    "2" -> "4" [dir=forward tooltip="include"]
    "2" -> "5" [dir=forward tooltip="include"]
    "2" -> "6" [dir=forward tooltip="include"]
    "2" -> "7" [dir=forward tooltip="include"]
    "2" -> "8" [dir=forward tooltip="include"]
    "2" -> "16" [dir=forward tooltip="include"]
    "2" -> "14" [dir=forward tooltip="include"]
    "2" -> "10" [dir=forward tooltip="include"]
    "9" -> "10" [dir=forward tooltip="include"]
    "10" -> "11" [dir=forward tooltip="include"]
    "10" -> "12" [dir=forward tooltip="include"]
    "10" -> "13" [dir=forward tooltip="include"]
    "10" -> "4" [dir=forward tooltip="include"]
    "1" -> "2" [dir=forward tooltip="include"]
    "1" -> "3" [dir=forward tooltip="include"]
    "1" -> "4" [dir=forward tooltip="include"]
}

This graph shows which files directly or indirectly include bitstring.h:

digraph {
    graph [bgcolor="#00000000"]
    node [shape=rectangle style=filled fillcolor="#FFFFFF" font=Helvetica padding=2]
    edge [color="#1414CE"]
    "4" [label="/__w/AtomVM/AtomVM/src/libAtomVM/interop.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/interop.c"]
    "5" [label="/__w/AtomVM/AtomVM/src/libAtomVM/nifs.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/nifs.c"]
    "3" [label="/__w/AtomVM/AtomVM/src/libAtomVM/externalterm.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/externalterm.c"]
    "2" [label="/__w/AtomVM/AtomVM/src/libAtomVM/bitstring.c" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/bitstring.c"]
    "1" [label="/__w/AtomVM/AtomVM/src/libAtomVM/bitstring.h" tooltip="/__w/AtomVM/AtomVM/src/libAtomVM/bitstring.h" fillcolor="#BFBFBF"]
    "1" -> "2" [dir=back tooltip="include"]
    "1" -> "3" [dir=back tooltip="include"]
    "1" -> "4" [dir=back tooltip="include"]
    "1" -> "5" [dir=back tooltip="include"]
}

Defines

READ_16LE_UNALIGNED(ptr)         ( (((uint8_t *)(ptr))[0] << 8) | ((uint8_t *)(ptr))[1] )
WRITE_16LE_UNALIGNED(t, ptr, val)         *((t *) (ptr)) = ( (((uint8_t *)(&val))[0] << 8) | ((uint8_t *)(&val))[1] )
READ_32LE_UNALIGNED(ptr)         ( (((uint8_t *)(ptr))[0] << 24) | (((uint8_t *) (ptr))[1] << 16) | (((uint8_t *)(ptr))[2] << 8) | ((uint8_t *)(ptr))[3] )
WRITE_32LE_UNALIGNED(t, ptr, val)         *((t *) (ptr)) = ( (((uint8_t *)(&val))[0] << 24) | (((uint8_t *) (&val))[1] << 16) | (((uint8_t *)(&val))[2] << 8) | ((uint8_t *)(&val))[3] )
READ_64LE_UNALIGNED(ptr)

( (((uint64_t) ((uint8_t *)(ptr))[0]) << 56) | (((uint64_t) ((uint8_t *) (ptr))[1]) << 48) | \

(((uint64_t) ((uint8_t *)(ptr))[2]) << 40) | (((uint64_t) ((uint8_t *) (ptr))[3]) << 32) | \

(((uint64_t) ((uint8_t *)(ptr))[4]) << 24) | (((uint64_t) ((uint8_t *) (ptr))[5]) << 16) | \

(((uint64_t) ((uint8_t *)(ptr))[6]) << 8) | (((uint64_t) ((uint8_t *) (ptr))[7])) )


WRITE_64LE_UNALIGNED(t, ptr, val)

*((t *) (ptr)) = ( \

((t) ((uint8_t *)(&val))[0] << 56) | ((t) ((uint8_t *) (&val))[1] << 48) | \

((t) ((uint8_t *)(&val))[2] << 40) | ((t) ((uint8_t *) (&val))[3] << 32) | \

((t) ((uint8_t *)(&val))[4] << 24) | ((t) ((uint8_t *) (&val))[5] << 16) | \

((t) ((uint8_t *)(&val))[6] <<  8) | (     (uint8_t *) (&val))[7] \

)


Enums

enum BitstringFlags

Values:

enumerator LittleEndianInteger = 0x2
enumerator SignedInteger = 0x4
enumerator NativeEndianInteger = 0x10
enumerator LittleEndianIntegerMask = LittleEndianInteger
enum UnicodeTransformDecodeResult

Values:

enumerator UnicodeTransformDecodeSuccess
enumerator UnicodeTransformDecodeFail
enumerator UnicodeTransformDecodeIncomplete

Functions

bool bitstring_extract_any_integer(const uint8_t *src, size_t offset, avm_int_t n, enum BitstringFlags bs_flags, union maybe_unsigned_int64 *dst)
bool bitstring_insert_any_integer(uint8_t *dst, avm_int_t offset, avm_int64_t value, size_t n, enum BitstringFlags bs_flags)
static inline bool bitstring_extract_integer(term src_bin, size_t offset, avm_int_t n, enum BitstringFlags bs_flags, union maybe_unsigned_int64 *dst)
static inline bool bitstring_insert_integer(term dst_bin, size_t offset, avm_int64_t value, size_t n, enum BitstringFlags bs_flags)
bool bitstring_utf8_encode(uint32_t c, uint8_t *buf, size_t *out_size)

Encode a character to UTF-8.

Parameters:
  • c – character to encode

  • buf – the buffer to encode the sring to or NULL to only compute the size.

  • out_size – the size in bytes, on output (if not NULL)

Returns:

true if encoding was successful, false if c is not a valid unicode character

enum UnicodeTransformDecodeResult bitstring_utf8_decode(const uint8_t *buf, size_t len, uint32_t *c, size_t *out_size)

Decode a character from UTF-8.

Parameters:
  • buf – the buffer from which to decode the string

  • len – the length (in bytes) of the bytes in buf

  • c – int value to decode to or NULL to only compute the size.

  • out_size – the size in bytes, on output (if not NULL)

Returns:

UnicodeTransformDecodeSuccess if decoding was successful, UnicodeTransformDecodeFail if character starting at buf is not a valid unicode character or UnicodeTransformDecodeIncomplete if character starting at buf is a valid but incomplete transformation

bool bitstring_utf16_encode(uint32_t c, uint8_t *buf, enum BitstringFlags bs_flags, size_t *out_size)

Encode a character to UTF-16.

Parameters:
  • c – character to encode

  • buf – the buffer to encode the character to or NULL to only compute the size.

  • bs_flags – flags to encode the character (undefined/little/big/native)

  • out_size – the size in bytes, on output (if not NULL)

Returns:

true if encoding was successful, false if c is not a valid unicode character

bool bitstring_utf16_decode(const uint8_t *buf, size_t len, int32_t *c, size_t *out_size, enum BitstringFlags bs_flags)

Decode a character from UTF-16.

Parameters:
  • c – int value to decode to

  • buf – the buffer froom which to decode the sring to or NULL to only compute the size.

  • len – the length (in bytes) of the bytes in buf

  • bs_flags – flags to decode the character (undefined/little/big/native)

  • out_size – the size in bytes, on output (if not NULL)

Returns:

true if decoding was successful, false if character starting at buf is not a valid unicode character

bool bitstring_utf32_encode(uint32_t c, uint8_t *buf, enum BitstringFlags bs_flags)

Encode a character to UTF-32.

Parameters:
  • c – character to encode

  • buf – the buffer to encode the character

  • bs_flags – flags to encode the character (undefined/little/big/native)

Returns:

true if encoding was successful, false if c is not a valid unicode character

bool bitstring_utf32_decode(const uint8_t *buf, size_t len, int32_t *c, enum BitstringFlags bs_flags)

Decode a character from UTF-32.

Parameters:
  • c – int value to decode to

  • buf – the buffer froom which to decode the sring to or NULL to only compute the size.

  • len – the length (in bytes) of the bytes in buf

  • bs_flags – flags to decode the character (undefined/little/big/native)

Returns:

true if decoding was successful, false if character starting at buf is not a valid unicode character

static inline bool bitstring_utf8_size(uint32_t c, size_t *out_size)

Compute the size of a character when UTF-8 encoded.

Parameters:
  • c – character to encode

  • out_size – the size in bytes, on output

Returns:

true if encoding was successful, false if c is not a valid unicode character

static inline bool bitstring_utf16_size(uint32_t c, size_t *out_size)

Compute the size of a unicode character when UTF-16 encoded.

Parameters:
  • c – character to encode

  • out_size – the size in bytes, on output

Returns:

true if encoding was successful, false if c is not a valid unicode character

static inline bool bitstring_insert_utf8(term dst_bin, size_t offset, uint32_t c, size_t *out_size)

Insert a character in UTF-8 format.

Parameters:
  • dst_bin – binary to insert to

  • offset – offset, in bits, to where to insert the character

  • c – character to encode

  • out_size – the size in bytes, on output

Returns:

true if encoding was successful, false if c is not a valid unicode character

static inline bool bitstring_match_utf8(term src_bin, size_t offset, uint32_t *c, size_t *out_size)

Match a character in UTF-8 format.

Parameters:
  • src_bin – binary to match against

  • offset – offset, in bits, to where to start to match the character

  • c – int to decode to

  • out_size – the size in bytes, on output

Returns:

true if encoding was successful, false if src_bin at offset is not a valid unicode character

static inline bool bitstring_insert_utf16(term dst_bin, size_t offset, uint32_t c, enum BitstringFlags bs_flags, size_t *out_size)

Insert a character in UTF-&§ format.

Parameters:
  • dst_bin – binary to insert to

  • offset – offset, in bits, to where to insert the character

  • c – character to encode

  • bs_flags – flags to encode the character (undefined/little/big/native)

  • out_size – the size in bytes, on output

Returns:

true if encoding was successful, false if c is not a valid unicode character

static inline bool bitstring_match_utf16(term src_bin, size_t offset, int32_t *c, size_t *out_size, enum BitstringFlags bs_flags)

Match a character in UTF-16 format.

Parameters:
  • src_bin – binary to match against

  • offset – offset, in bits, to where to start to match the character

  • c – int to decode to

  • bs_flags – flags to decode the character (undefined/little/big/native)

  • out_size – the size in bytes, on output

Returns:

true if encoding was successful, false if src_bin at offset is not a valid unicode character

static inline bool bitstring_insert_utf32(term dst_bin, size_t offset, uint32_t c, enum BitstringFlags bs_flags)

Insert a character in UTF-32 format.

Parameters:
  • dst_bin – binary to insert to

  • offset – offset, in bits, to where to insert the character

  • c – character to encode

  • bs_flags – flags to encode the character (undefined/little/big/native)

Returns:

true if encoding was successful, false if c is not a valid unicode character

static inline bool bitstring_match_utf32(term src_bin, size_t offset, int32_t *c, enum BitstringFlags bs_flags)

Match a character in UTF-32 format.

Parameters:
  • src_bin – binary to match against

  • offset – offset, in bits, to where to start to match the character

  • c – int to decode to

  • bs_flags – flags to decode the character (undefined/little/big/native)

Returns:

true if encoding was successful, false if src_bin at offset is not a valid unicode character

void bitstring_copy_bits_incomplete_bytes(uint8_t *dst, size_t bits_offset, const uint8_t *src, size_t bits_count)

Copy bits_count bits from src to dst[bits_offset..].

Called by bitstring_copy_bits when bytes are not complete.

Parameters:
  • dst – destination buffer

  • bits_offset – offset in bits in destination buffer

  • src – source buffer

  • bits_count – number of bits

static inline void bitstring_copy_bits(uint8_t *dst, size_t bits_offset, const uint8_t *src, size_t bits_count)

Copy bits_count bits from src to dst[bits_offset..].

Parameters:
  • dst – destination buffer

  • bits_offset – offset in bits in destination buffer

  • src – source buffer

  • bits_count – number of bits

bool bitstring_extract_f32(term src_bin, size_t offset, avm_int_t n, enum BitstringFlags bs_flags, avm_float_t *dst)
bool bitstring_extract_f64(term src_bin, size_t offset, avm_int_t n, enum BitstringFlags bs_flags, avm_float_t *dst)
union maybe_unsigned_int8
#include <bitstring.h>

Public Members

uint8_t u
int8_t s
union maybe_unsigned_int16
#include <bitstring.h>

Public Members

uint16_t u
int16_t s
union maybe_unsigned_int32
#include <bitstring.h>

Public Members

uint32_t u
int32_t s
union maybe_unsigned_int64
#include <bitstring.h>

Public Members

uint64_t u
int64_t s