fastjson

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(input interface{}, output interface{}) error

func DecodeHookExec

func DecodeHookExec(
	raw DecodeHookFunc,
	from reflect.Value, to reflect.Value) (interface{}, error)

DecodeHookExec executes the given decode hook. This should be used since it'll naturally degrade to the older backwards compatible DecodeHookFunc that took reflect.Kind instead of reflect.Type.

func DecodeMetadata

func DecodeMetadata(input interface{}, output interface{}, metadata *Metadata) error

func Marshal

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

func Unmarshal

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

func WeakDecode

func WeakDecode(input, output interface{}) error

func WeakDecodeMetadata

func WeakDecodeMetadata(input interface{}, output interface{}, metadata *Metadata) error

WeakDecodeMetadata is the same as Decode, but is shorthand to enable both WeaklyTypedInput and metadata collection. See DecoderConfig for more info.

func WeaklyTypedHook

func WeaklyTypedHook(
	f reflect.Kind,
	t reflect.Kind,
	data interface{}) (interface{}, error)

WeaklyTypedHook is a DecodeHookFunc which adds support for weak typing to the decoder.

Note that this is significantly different from the WeaklyTypedInput option of the DecoderConfig.

Types

type DecodeHookFunc

type DecodeHookFunc interface{}

func ComposeDecodeHookFunc

func ComposeDecodeHookFunc(fs ...DecodeHookFunc) DecodeHookFunc

ComposeDecodeHookFunc creates a single DecodeHookFunc that automatically composes multiple DecodeHookFuncs.

The composed funcs are called in order, with the result of the previous transformation.

func RecursiveStructToMapHookFunc

func RecursiveStructToMapHookFunc() DecodeHookFunc

func StringToIPHookFunc

func StringToIPHookFunc() DecodeHookFunc

StringToIPHookFunc returns a DecodeHookFunc that converts strings to net.IP

func StringToIPNetHookFunc

func StringToIPNetHookFunc() DecodeHookFunc

StringToIPNetHookFunc returns a DecodeHookFunc that converts strings to net.IPNet

func StringToSliceHookFunc

func StringToSliceHookFunc(sep string) DecodeHookFunc

StringToSliceHookFunc returns a DecodeHookFunc that converts string to []string by splitting on the given sep.

func StringToTimeDurationHookFunc

func StringToTimeDurationHookFunc() DecodeHookFunc

StringToTimeDurationHookFunc returns a DecodeHookFunc that converts strings to time.Duration.

func StringToTimeHookFunc

func StringToTimeHookFunc(layout string) DecodeHookFunc

StringToTimeHookFunc returns a DecodeHookFunc that converts strings to time.Time.

type DecodeHookFuncKind

type DecodeHookFuncKind func(reflect.Kind, reflect.Kind, interface{}) (interface{}, error)

type DecodeHookFuncType

type DecodeHookFuncType func(reflect.Type, reflect.Type, interface{}) (interface{}, error)

func TextUnmarshallerHookFunc

func TextUnmarshallerHookFunc() DecodeHookFuncType

TextUnmarshallerHookFunc returns a DecodeHookFunc that applies strings to the UnmarshalText function, when the target type implements the encoding.TextUnmarshaler interface

type DecodeHookFuncValue

type DecodeHookFuncValue func(from reflect.Value, to reflect.Value) (interface{}, error)

type Decoder

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

func NewDecoder

func NewDecoder(config *DecoderConfig) (*Decoder, error)

NewDecoder returns a new decoder for the given configuration. Once a decoder has been returned, the same configuration must not be used again.

func (*Decoder) Decode

func (d *Decoder) Decode(input interface{}) error

Decode decodes the given raw interface to the target pointer specified by the configuration.

type DecoderConfig

type DecoderConfig struct {
	DecodeHook       DecodeHookFunc
	ErrorUnused      bool
	ZeroFields       bool
	WeaklyTypedInput bool
	Squash           bool
	Metadata         *Metadata
	Result           interface{}
	TagName          string
}

type Error

type Error struct {
	Errors []string
}

Error implements the error interface and can represents multiple errors that occur in the course of a single decode.

func (*Error) Error

func (e *Error) Error() string

func (*Error) WrappedErrors

func (e *Error) WrappedErrors() []error

WrappedErrors implements the errwrap.Wrapper interface to make this return value more useful with the errwrap and go-multierror libraries.

type Metadata

type Metadata struct {
	Keys   []string
	Unused []string
}

Jump to

Keyboard shortcuts

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