jsonutil

package
v1.40.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2023 License: BSD-3-Clause Imports: 3 Imported by: 0

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

func Unmarshal(b []byte, v any) error

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.

func (*Bytes) UnmarshalText

func (b *Bytes) UnmarshalText(text []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL