Function jsonb::from_slice
source · 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
,True
andFalse
can be obtained byJEntry
, no extra work required.Number
andString
has relatedRawData
,JEntry
store the length or offset of this data, theValue
can be read out and then decoded.Container
is actually a nestedArray
orObject
with the same structure,JEntry
store the length or offset of the lower-levelHeader
, from where the same decode process can begin.RawData
is the encodedValue
.Number
is a variable-lengthDecimal
, store both int and float value.String
is the original string, can be borrowed directly without extra decode.Array
andObject
is a lower-level encodedJSONB
value. The upper-level doesn’t care about the specific content. Decode can be executed recursively. DecodeJSONB
Value from binary bytes.