Erlang structure that compiles to BERT format:
Target structure of bert.js — fast low-level handcoded parser from BERT format.
Target structure of generated parser with RPC parse transform:
The following practical subset of BERT format is supported:
IEEE-754 float encoding. A float is stored as 8 bytes in big-endian IEEE format. This term is used in minor version 1 of the external format.
Byte encoding. Unsigned 8-bit integer.
Integer encoding. Signed 32-bit integer in big-endian format.
Float POSIX encoding. A float is stored in string format. The format used in sprintf to format the float is "%.20e" (there are more bytes allocated than necessary). To unpack the float, use sscanf with format "%lf".
Atom encoding. An atom is stored with a 2 byte unsigned length in big-endian order, followed by N numbers of 8-bit Latin-1 characters that forms the name. The maximum allowed value for Len is 255.
Tuple encoding. The Arity field is an unsigned byte N that determines how many elements that follows in section Elements.
Large tuple encoding. Same as 104 except that N is an unsigned 4 byte integer in big-endian format.
String encoding. As field N is an unsigned 2 byte integer (big-endian), implementations must ensure that lists longer than 65535 elements are encoded as 108.
List encoding. N is the number of elements that follows in section Characters. Tail is the final tail of the list; it is 106 for a proper list, but can be any type if the list is improper (for example, [a|b]).
Binary encoding. Binaries are generated with bit syntax expression or with erlang:list_to_binary/1, erlang:term_to_binary/1, or as input from binary ports. The N length field is an unsigned 4 byte integer (big-endian).
Small bignum encoding. Bignums are stored in unary form with a Sign byte, that is, 0 if the binum is positive and 1 if it is negative. The digits are stored with the least significant byte stored first. To calculate the integer, the following formula can be used:
B = 256,
d0*B0 + d1*B1 + d2*B2 + ... dN-1*B(n-1)
Large bignum encoding. Same as 110 except that the length field is an unsigned 4 byte integer.
Small atom encoding. An atom is stored with a 1 byte unsigned length, followed by N numbers of 8-bit Latin-1 characters that forms the Characters.
Maps encoding. The N field is an unsigned 4 byte integer in big-endian format that determines the number of key-value pairs in the map. Key and value pairs (Ki => Vi) are encoded in section Pairs in the following order: K1, V1, K2, V2,..., Kn, Vn. Duplicate keys are not allowed within the same map. Requires OTP 17.
UTF8 atom encoding. An atom is stored with a 2 byte unsigned length in big-endian order, followed by N bytes containing the Characters encoded in UTF-8.
UTF8 small atom encoding. An atom is stored with a 1 byte unsigned length, followed by N bytes containing the Characters encoded in UTF-8. Longer atoms encoded in UTF-8 can be represented using 118.
Encodes internal JSON to binary buffer.
Decodes binary buffer to internal JSON.
Creates JSON for binary encoding.
Creates JSON for Latin-1 atom encoding.
Creates JSON for string encoding.
Creates JSON for IEEE-754 float encoding.
Creates JSON for integers and GMP big numbers encoding.
Creates JSON for list encoding.
Creates JSON for tuple encoding.
Creates JSON for map encoding.
You may also want to read: utf8.js, ieee754.js, heart.js, nitro.js, mq.js, n2o.js.