encoder

package
v1.0.0-rc Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2021 License: Apache-2.0 Imports: 20 Imported by: 29

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(val interface{}, opts Options) ([]byte, error)

Encode returns the JSON encoding of val, encoded with opts.

func EncodeIndented

func EncodeIndented(val interface{}, prefix string, indent string, opts Options) ([]byte, error)

EncodeIndented is like Encode but applies Indent to format the output. Each JSON element in the output will begin on a new line beginning with prefix followed by one or more copies of indent according to the indentation nesting.

func EncodeInto

func EncodeInto(buf *[]byte, val interface{}, opts Options) error

EncodeInto is like Encode but uses a user-supplied buffer instead of allocating a new one.

func Pretouch

func Pretouch(vt reflect.Type) (err error)

Pretouch compiles vt ahead-of-time to avoid JIT compilation on-the-fly, in order to reduce the first-hit latency.

func Quote

func Quote(s string) string

Quote returns the JSON-quoted version of s.

Types

type Encoder

type Encoder struct {
	Opts Options
}

Encoder represents a specific set of encoder configurations.

func (*Encoder) Encode

func (self *Encoder) Encode(v interface{}) ([]byte, error)

Encode returns the JSON encoding of v.

func (*Encoder) SortKeys

func (self *Encoder) SortKeys() *Encoder

SortKeys enables the SortMapKeys option.

type Options

type Options uint64

Options is a set of encoding options.

const (
	// SortMapKeys indicate that the keys of a map needs to be sorted before
	// serializing into JSON.
	// WARNING: This hurts performance A LOT, USE WITH CARE.
	SortMapKeys Options = 1 << bitSortMapKeys
)

Jump to

Keyboard shortcuts

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