ffjson

package
v0.0.0-...-aa0246c Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2019 License: Apache-2.0 Imports: 6 Imported by: 637

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal will act the same way as json.Marshal, except it will choose the ffjson marshal function before falling back to using json.Marshal. Using this function will bypass the internal copying and parsing the json library normally does, which greatly speeds up encoding time. It is ok to call this function even if no ffjson code has been generated for the data type you pass in the interface.

func MarshalFast

func MarshalFast(v interface{}) ([]byte, error)

MarshalFast will marshal the data if fast marshal is available. This function can be used if you want to be sure the fast marshal is used or in testing. If you would like to have fallback to encoding/json you can use the Marshal() method.

func Pool

func Pool(b []byte)

Send a buffer to the Pool to reuse for other instances.

On servers where you have a lot of concurrent encoding going on, you can hand back the byte buffer you get marshalling once you are done using it.

You may no longer utilize the content of the buffer, since it may be used by other goroutines.

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal will act the same way as json.Unmarshal, except it will choose the ffjson unmarshal function before falling back to using json.Unmarshal. The overhead of unmarshal is lower than on Marshal, however this should still provide a speedup for your encoding. It is ok to call this function even if no ffjson code has been generated for the data type you pass in the interface.

func UnmarshalFast

func UnmarshalFast(data []byte, v interface{}) error

UnmarshalFast will unmarshal the data if fast marshall is available. This function can be used if you want to be sure the fast unmarshal is used or in testing. If you would like to have fallback to encoding/json you can use the Unmarshal() method.

Types

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

This is a reusable decoder. This should not be used by more than one goroutine at the time.

func NewDecoder

func NewDecoder() *Decoder

NewDecoder returns a reusable Decoder.

func (*Decoder) Decode

func (d *Decoder) Decode(data []byte, v interface{}) error

Decode the data in the supplied data slice.

func (*Decoder) DecodeFast

func (d *Decoder) DecodeFast(data []byte, v interface{}) error

DecodeFast will unmarshal the data if fast unmarshal is available. This function can be used if you want to be sure the fast unmarshal is used or in testing. If you would like to have fallback to encoding/json you can use the regular Decode() method.

func (*Decoder) DecodeReader

func (d *Decoder) DecodeReader(r io.Reader, v interface{}) error

Decode the data from the supplied reader. You should expect that data is read into memory before it is decoded.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

This is a reusable encoder. It allows to encode many objects to a single writer. This should not be used by more than one goroutine at the time.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a reusable Encoder. Output will be written to the supplied writer.

func (*Encoder) Encode

func (e *Encoder) Encode(v interface{}) error

Encode the data in the supplied value to the stream given on creation. When the function returns the output has been written to the stream.

func (*Encoder) EncodeFast

func (e *Encoder) EncodeFast(v interface{}) error

EncodeFast will unmarshal the data if fast marshall is available. This function can be used if you want to be sure the fast marshal is used or in testing. If you would like to have fallback to encoding/json you can use the regular Encode() method.

func (*Encoder) SetEscapeHTML

func (enc *Encoder) SetEscapeHTML(on bool)

SetEscapeHTML specifies whether problematic HTML characters should be escaped inside JSON quoted strings. The default behavior is to escape &, <, and > to \u0026, \u003c, and \u003e to avoid certain safety problems that can arise when embedding JSON in HTML.

In non-HTML settings where the escaping interferes with the readability of the output, SetEscapeHTML(false) disables this behavior.

Jump to

Keyboard shortcuts

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