Documentation ¶
Overview ¶
Package jsonutil provides utilities to improve JSON performance. It includes an Unmarshal wrapper that amortizes allocated garbage over subsequent runs and a Bytes type to reduce allocations when unmarshalling a non-hex-encoded string into a []byte.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Unmarshal ¶
Unmarshal is similar to encoding/json.Unmarshal. There are three major differences:
On error, encoding/json.Unmarshal zeros v. This Unmarshal may leave partial data in v. Always check the error before using v! (Future improvements may remove this bug.)
The errors they return don't always match perfectly. If you do error matching more precise than err != nil, don't use this Unmarshal.
This Unmarshal allocates considerably less memory.
Types ¶
type Bytes ¶
type Bytes []byte
Bytes is a byte slice in a json-encoded struct. encoding/json assumes that []byte fields are hex-encoded. Bytes are not hex-encoded; they are treated the same as strings. This can avoid unnecessary allocations due to a round trip through strings.