pub fn from_slice(buf: &[u8]) -> Result<Value<'_>, Error>Expand description
The binary JSONB contains three parts, Header, JEntry and RawData.
This structure can be nested. Each group of structures starts with a Header.
The upper-level Value will store the Header length or offset of
the lower-level Value.
Header stores the type of the Value, include Array, Object and Scalar,
Scalar has only one Value, and a corresponding JEntry.
Array and Object are nested type, they have multiple lower-level Values.
So the Header also stores the number of lower-level Values.
JEntry stores the types of Scalar Value, including Null, True, False,
Number, String and Container. They have three different decode methods.
-
Null,TrueandFalsecan be obtained byJEntry, no extra work required. -
NumberandStringhas relatedRawData,JEntrystore the length or offset of this data, theValuecan be read out and then decoded. -
Containeris actually a nestedArrayorObjectwith the same structure,JEntrystore the length or offset of the lower-levelHeader, from where the same decode process can begin.RawDatais the encodedValue.Numberis a variable-lengthDecimal, store both int and float value.Stringis the original string, can be borrowed directly without extra decode.ArrayandObjectis a lower-level encodedJSONBvalue. The upper-level doesn’t care about the specific content. Decode can be executed recursively.Decode
JSONBValue from binary bytes.