yyjson 0.5.0
A high performance C JSON library.
|
yyjson has 2 types of data structures: immutable and mutable.
When reading a JSON, yyjson returns immutable document and values;
When building a JSON, yyjson creates mutable document and values.
yyjson also provides some methods to convert immutable document into mutable document.
Note that the data structures described in this document are private, and you should use public API to access them.
Each JSON value is stored in an immutable yyjson_val
struct:
The lower 8 bits of tag
stores the type of value.
The higher 56 bits of tag
stores the size of value (string length, object size or array size).
Modern 64-bit processors are typically limited to supporting fewer than 64 bits for RAM addresses (Wikipedia). For example, Intel64, AMD64 and ARMv8 has a 52-bit (4PB) physical address limit. So we can safely store type and size into a 64 bits tag
.
A JSON document stores all strings in a contiguous memory area.
Each string is unescaped in-place and ended with a null-terminator.
For example:
A JSON document stores all values in another contiguous memory area.
The object
and array
stores their own memory usage, so we can easily walk through a container's child values.
For example:
Each mutable JSON value is stored in an yyjson_mut_val
struct:
The tag
and uni
field is same as immutable value, the next
field is used to build linked list.
A mutable JSON document is composed of multiple yyjson_mut_val
.
The child values of an object
or array
are linked as a cycle,
the parent hold the tail of the linked list, so yyjson can do append
, prepend
and remove_first
in O(1) time.
For example: