jzon

package module
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2022 License: MIT Imports: 19 Imported by: 1

README

Go Report Card PkgGoDev Github Workflow Build Status codecov pre-commit

jzon

A high performance json library for Golang

Why another jsoniter?

The code I write here is very similar to github.com/json-iterator/go, so you may ask why reinvent the wheel.

For sure that I benefit a lot from the jsoniter library, but i found some inconvenience for me to use it in some condition, for example:

  • the iterator methods ReadString accepts null, there is no method which accepts exactly string. I have to do some extra check before calling.
  • some behavior is not compatible with the standard library.
  • I want a chained streamer

On the other hand, I also want to learn how the jsoniter works, so there is this repo.

What's different from jsoniter?

Here are some of the differences:

  • the iterator methods accept the exact type, for example ReadString accepts only string, not null
  • the behavior is almost the same as the standard library (when an error returns, the behavior may differ from the standard library)
  • the error of the iterator is returned instead of being saved inside iterator
  • the decoder/encoder interface has additional options, like struct tag options

Some features of jsoniter are not implemented, and may be not implemented in the future neither. I choose only the ones I need to implement.

Compatibility with standard library

I tried implemented a version which is completely compatible with the standard library:

https://github.com/zerosnake0/jzon/tree/reflect

The benchmark shows that it's much faster than the standard library. However it is still much slower than the current version, which cannot be exactly the same as standard library (at least in my POV).

The major incompatibility is about the two following interfaces:

  • json.Marshaler
  • encoding.TextMarshaler

The method on pointer receiver may be called with an unaddressable value, for example:

type field struct {}

func (*field) MarshalJSON() ([]byte, error)

type st struct {
    F field
}

json.Marshal(st{}) // will not call field.MarshalJSON
jzon.Marshal(st{}) // will call field.MarshalJSON

So the user should be care when marshaling a value when method on pointer receiver is involved

You can check the tests for more detailed info about the difference

How to use

Standard library like
import "github.com/zerosnake0/jzon"

// Unmarshal
err := jzon.Unmarshal(b, &data)

// Marshal
b, err := jzon.Marshal(&data)

// Decoder
dec := jzon.NewDecoder(reader)
defer dec.Release()
err := dec.Decode(&data)

// Encoder
enc := jzon.NewEncoder(writer)
defer enc.Release()
err := enc.Encode(&data)
Iterator
iter := jzon.NewIterator()
defer iter.Release()
iter.Reset(b)
jzon.ReadVal(&data)
Streamer
var w io.Writer

streamer := jzon.NewStreamer()
defer streamer.Release()
streamer.Reset(w)
streamer.Value(&data)
streamer.Flush()
Custom Decoder

see decoder_test.go

type testIntDecoder struct{}

func (*testIntDecoder) Decode(ptr unsafe.Pointer, it *Iterator, opts *DecOpts) error {
    ...
}

dec := NewDecoderConfig(&DecoderOption{
    ValDecoders: map[reflect.Type]ValDecoder{
        reflect.TypeOf(int(0)): (*testIntDecoder)(nil),
    },
    CaseSensitive: true,
})

// standard library like
err := dec.Unmarshal(b, &data)

// iterator
iter := dec.NewIterator()
defer iter.Release()
Custom Encoder

see encoder_test.go

type testIntEncoder struct{}

func (*testIntEncoder) IsEmpty(ptr unsafe.Pointer) bool {
    ...
}

func (*testIntEncoder) Encode(ptr unsafe.Pointer, s *Streamer, opts *EncOpts) {
    ...
}

enc := NewEncoderConfig(&EncoderOption{
    ValEncoders: map[reflect.Type]ValEncoder{
        reflect.TypeOf(int(0)): (*testIntEncoder)(nil),
    },
})

// standard library like
b, err := enc.Marshal(&data)

// streamer
streamer := enc.NewStreamer()
defer streamer.Release()

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultDecoderConfig is compatible with standard lib
	DefaultDecoderConfig = NewDecoderConfig(nil)
)
View Source
var (
	// DefaultEncoderConfig is compatible with standard lib
	DefaultEncoderConfig = NewEncoderConfig(nil)
)
View Source
var ErrDataRemained = errors.New("expecting EOF, but there is still data")

ErrDataRemained there is still data remained in the buffer normally returned by Unmarshal methods

View Source
var ErrEfaceLooping = errors.New("eface looping detected")

ErrEfaceLooping if we encountered a loop for example:

type iface interface{}
var o1 iface
o1 = &o1
err := DefaultDecoderConfig.Unmarshal([]byte(`1`), o1)
View Source
var ErrEmptyIFace = errors.New("cannot unmarshal on empty iface")

ErrEmptyIFace if the decode target is an empty interface (with method)

View Source
var ErrFloatIsInfinity = errors.New("float is infinity")

ErrFloatIsInfinity the float to write is infinity

View Source
var ErrFloatIsNan = errors.New("float is NaN")

ErrFloatIsNan the float to write is NaN

View Source
var ErrNilEmbeddedPointer = errors.New("cannot unmarshal on nil pointer (unexported embedded)")

ErrNilEmbeddedPointer if the decode target has an unexported nil field

View Source
var ErrNilPointerReceiver = errors.New("the receiver is nil")

ErrNilPointerReceiver if the decode target is nil

View Source
var ErrNoAttachedWriter = errors.New("no attached writer")

ErrNoAttachedWriter there is no writer attaching to the streamer

View Source
var ErrPointerReceiver = errors.New("the receiver is not a pointer")

ErrPointerReceiver if the decode target is not a pointer

Functions

func Marshal

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

Marshal returns the JSON encoding of object

func Unmarshal

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

Unmarshal parses the JSON-encoded data and stores the result in the value pointed to

func UnmarshalFromReader added in v0.0.4

func UnmarshalFromReader(r io.Reader, o interface{}) error

UnmarshalFromReader behave like json.Unmarshal but with an io.Reader

func UnmarshalFromString added in v0.0.6

func UnmarshalFromString(s string, o interface{}) error

UnmarshalFromString behave like json.Unmarshal but with a string

func Valid

func Valid(data []byte) bool

Valid reports whether data is a valid JSON encoding.

Types

type BadQuotedStringError

type BadQuotedStringError string

BadQuotedStringError the value of field is not correctly quoted

func (BadQuotedStringError) Error

func (e BadQuotedStringError) Error() string

type DecOpts

type DecOpts struct {
	MapKey bool
	Quoted bool
}

DecOpts is the context related decoding option of the object

type DecodeError

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

DecodeError describes the encountered error and its location.

func (*DecodeError) Error

func (e *DecodeError) Error() string

type Decoder

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

Decoder is almost standard library compatible The following standard methods are not implemented - Token

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reads from r.

func (*Decoder) Buffered added in v0.0.5

func (dec *Decoder) Buffered() io.Reader

Buffered returns a reader of the data remaining in the Decoder's buffer. The reader is valid until the next call to Decode.

func (*Decoder) Decode added in v0.0.5

func (dec *Decoder) Decode(v interface{}) error

Decode reads the next JSON-encoded value from its input and stores it in the value pointed to by v.

func (*Decoder) DisallowUnknownFields added in v0.0.5

func (dec *Decoder) DisallowUnknownFields()

DisallowUnknownFields causes the Decoder to return an error when the destination is a struct and the input contains object keys which do not match any non-ignored, exported fields in the destination.

func (*Decoder) InputOffset added in v0.0.5

func (dec *Decoder) InputOffset() int64

InputOffset returns the input stream byte offset of the current decoder position. The offset gives the location of the end of the most recently returned token and the beginning of the next token. Whitespace may present at the position of offset

func (*Decoder) More added in v0.0.5

func (dec *Decoder) More() bool

More reports whether there is another element in the current array or object being parsed.

func (*Decoder) Release added in v0.0.5

func (dec *Decoder) Release()

Release decoder, decoder should not be reused after call

func (*Decoder) UseNumber added in v0.0.5

func (dec *Decoder) UseNumber()

UseNumber causes the Decoder to unmarshal a number into an interface{} as a Number instead of as a float64.

type DecoderConfig added in v0.0.5

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

DecoderConfig is a frozen config for decoding

func NewDecoderConfig added in v0.0.5

func NewDecoderConfig(opt *DecoderOption) *DecoderConfig

NewDecoderConfig returns a new decoder config If the input option is nil, the default option will be applied

func (*DecoderConfig) NewDecoder added in v0.0.5

func (decCfg *DecoderConfig) NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reads from r.

func (*DecoderConfig) NewIterator added in v0.0.5

func (decCfg *DecoderConfig) NewIterator() *Iterator

NewIterator returns a new iterator.

func (*DecoderConfig) Unmarshal added in v0.0.5

func (decCfg *DecoderConfig) Unmarshal(data []byte, obj interface{}) error

Unmarshal behave like json.Unmarshal

func (*DecoderConfig) UnmarshalFromReader added in v0.0.5

func (decCfg *DecoderConfig) UnmarshalFromReader(r io.Reader, obj interface{}) error

UnmarshalFromReader behave like json.Unmarshal but with an io.Reader

func (*DecoderConfig) UnmarshalFromString added in v0.0.5

func (decCfg *DecoderConfig) UnmarshalFromString(s string, obj interface{}) error

UnmarshalFromString behave like json.Unmarshal but with a string

type DecoderOption

type DecoderOption struct {
	// custom value decoders
	ValDecoders map[reflect.Type]ValDecoder

	// if the object key is case sensitive
	// `false` by default
	CaseSensitive bool

	// the tag name for structures
	// `json` by default
	Tag string

	OnlyTaggedField bool

	UseNumber bool

	DisallowUnknownFields bool
}

DecoderOption can be used to customize the decoder config

type EncOpts

type EncOpts struct {
	Quoted bool
}

EncOpts is the context related encoding option of the object

type Encoder

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

Encoder is almost standard library compatible The following standard methods are not implemented - SetIndent

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*Encoder) Encode added in v0.0.5

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

Encode writes the JSON encoding of v to the stream, followed by a newline character.

func (*Encoder) Release added in v0.0.5

func (e *Encoder) Release()

Release encoder, encoder should not be reused after call

func (*Encoder) SetEscapeHTML added in v0.0.5

func (e *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.

type EncoderConfig added in v0.0.5

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

EncoderConfig is a frozen config for encoding

func NewEncoderConfig added in v0.0.5

func NewEncoderConfig(opt *EncoderOption) *EncoderConfig

NewEncoderConfig returns a new encoder config If the input option is nil, the default option will be applied

func (*EncoderConfig) Marshal added in v0.0.5

func (encCfg *EncoderConfig) Marshal(obj interface{}) ([]byte, error)

Marshal behave like json.Marshal

func (*EncoderConfig) NewEncoder added in v0.0.5

func (encCfg *EncoderConfig) NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*EncoderConfig) NewStreamer added in v0.0.5

func (encCfg *EncoderConfig) NewStreamer() *Streamer

NewStreamer returns a new streamer.

type EncoderOption

type EncoderOption struct {
	ValEncoders map[reflect.Type]ValEncoder

	EscapeHTML      bool
	Tag             string
	OnlyTaggedField bool
}

EncoderOption can be used to customize the encoder config

type IntOverflowError

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

IntOverflowError the integer overflows.

func (IntOverflowError) Error

func (e IntOverflowError) Error() string

type InvalidDigitError

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

InvalidDigitError there is an invalid digit when reading number

func (InvalidDigitError) Error

func (e InvalidDigitError) Error() string

type InvalidEscapeCharError

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

InvalidEscapeCharError there is an invalid escape character (when reading string)

func (InvalidEscapeCharError) Error

func (e InvalidEscapeCharError) Error() string

type InvalidFloatError

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

InvalidFloatError there is an invalid digit when reading float

func (InvalidFloatError) Error

func (e InvalidFloatError) Error() string

type InvalidStringCharError

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

InvalidStringCharError there is an invalid character when reading string

func (InvalidStringCharError) Error

func (e InvalidStringCharError) Error() string

type InvalidUnicodeCharError

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

InvalidUnicodeCharError there is an invalid unicode character (when reading string)

func (InvalidUnicodeCharError) Error

func (e InvalidUnicodeCharError) Error() string

type Iterator

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

Iterator is designed for one-shot use, each reuse must call reset first

func NewIterator

func NewIterator() *Iterator

NewIterator returns a new iterator.

func (*Iterator) AppendRaw

func (it *Iterator) AppendRaw(in []byte) ([]byte, error)

AppendRaw is like SkipRaw but it is a copy version

func (*Iterator) Buffer

func (it *Iterator) Buffer() []byte

Buffer returns the current slice buffer of the iterator.

func (*Iterator) NextValueType

func (it *Iterator) NextValueType() (ValueType, error)

NextValueType read until the first valid token is found, only the whitespaces are consumed

func (*Iterator) Read

func (it *Iterator) Read() (interface{}, error)

Read reads a json object as a golang object

func (*Iterator) ReadArrayBegin

func (it *Iterator) ReadArrayBegin() (ret bool, err error)

ReadArrayBegin starts to read an array

var (

more bool
err error

) for more, err = it.ReadArray();

    more;
    more, err = it.ReadArrayMore() {
}
if err != nil {
    // error handling
}

func (*Iterator) ReadArrayCB

func (it *Iterator) ReadArrayCB(cb func(*Iterator) error) error

ReadArrayCB reads the array with a callback The caller should make sure that the callback is correct

func (*Iterator) ReadArrayMore

func (it *Iterator) ReadArrayMore() (ret bool, err error)

ReadArrayMore tells if there is more item to read in the array

func (*Iterator) ReadBool

func (it *Iterator) ReadBool() (bool, error)

ReadBool reads a boolean value

func (*Iterator) ReadFloat32

func (it *Iterator) ReadFloat32() (float32, error)

ReadFloat32 reads a float32 value

func (*Iterator) ReadFloat64

func (it *Iterator) ReadFloat64() (float64, error)

ReadFloat64 reads a float64 value

func (*Iterator) ReadInt

func (it *Iterator) ReadInt() (int, error)

ReadInt reads an int value

func (*Iterator) ReadInt16

func (it *Iterator) ReadInt16() (int16, error)

ReadInt16 reads an int16 value

func (*Iterator) ReadInt32

func (it *Iterator) ReadInt32() (int32, error)

ReadInt32 reads an int32 value

func (*Iterator) ReadInt64

func (it *Iterator) ReadInt64() (int64, error)

ReadInt64 reads an int64 value

func (*Iterator) ReadInt8

func (it *Iterator) ReadInt8() (int8, error)

ReadInt8 reads an int8 value

func (*Iterator) ReadNull

func (it *Iterator) ReadNull() error

ReadNull reads a nil

func (*Iterator) ReadNumber

func (it *Iterator) ReadNumber() (n Number, err error)

ReadNumber reads a Number(json.Number)

func (*Iterator) ReadObjectBegin

func (it *Iterator) ReadObjectBegin() (_ bool, _ string, err error)

ReadObjectBegin starts to read an object

func (*Iterator) ReadObjectCB

func (it *Iterator) ReadObjectCB(cb func(it *Iterator, field string) error) error

ReadObjectCB reads the object with a callback The caller should make sure that the callback is correct

func (*Iterator) ReadObjectMore

func (it *Iterator) ReadObjectMore() (_ bool, _ string, err error)

ReadObjectMore tells if there is more field to read in the object

func (*Iterator) ReadRaw

func (it *Iterator) ReadRaw() ([]byte, error)

ReadRaw reads a raw json object (slice will be copied)

func (*Iterator) ReadString

func (it *Iterator) ReadString() (_ string, err error)

ReadString reads a string

func (*Iterator) ReadStringAndAppend

func (it *Iterator) ReadStringAndAppend(buf []byte) (_ []byte, err error)

ReadStringAndAppend reads a string and appends to a byte slice

func (*Iterator) ReadStringAsSlice

func (it *Iterator) ReadStringAsSlice() (_ []byte, err error)

ReadStringAsSlice reads a string as a byte slice The returned slice can only be used temporarily, a copy must be made if the result needs to be saved

func (*Iterator) ReadUint

func (it *Iterator) ReadUint() (uint, error)

ReadUint reads an uint value

func (*Iterator) ReadUint16

func (it *Iterator) ReadUint16() (uint16, error)

ReadUint16 reads an uint16 value

func (*Iterator) ReadUint32

func (it *Iterator) ReadUint32() (uint32, error)

ReadUint32 reads an uint32 value

func (*Iterator) ReadUint64

func (it *Iterator) ReadUint64() (uint64, error)

ReadUint64 reads an uint64 value

func (*Iterator) ReadUint8

func (it *Iterator) ReadUint8() (uint8, error)

ReadUint8 reads an Uint8 value

func (*Iterator) ReadVal

func (it *Iterator) ReadVal(obj interface{}) error

ReadVal reads a json object and decode it to a golang object

func (*Iterator) Release added in v0.0.5

func (it *Iterator) Release()

Release the iterator, the iterator should not be reused after call.

func (*Iterator) Reset

func (it *Iterator) Reset(r io.Reader)

Reset the iterator with an io.Reader if the reader is nil, reset the iterator to its initial state

In reset methods, explicit assignment is faster than then following

*it = Iterator{ ... }

When the above code is used, runtime.duffcopy and runtime.duffzero will be used which will slow down our code (correct me if I am wrong)

func (*Iterator) ResetBytes

func (it *Iterator) ResetBytes(data []byte)

ResetBytes resets iterator with a byte slice

func (*Iterator) Skip

func (it *Iterator) Skip() error

Skip skips a json object

func (*Iterator) SkipArray

func (it *Iterator) SkipArray() error

SkipArray skips an array

func (*Iterator) SkipNumber

func (it *Iterator) SkipNumber() error

SkipNumber skips a number

func (*Iterator) SkipObject

func (it *Iterator) SkipObject() error

SkipObject skips an object

func (*Iterator) SkipRaw

func (it *Iterator) SkipRaw() ([]byte, error)

SkipRaw skips and returns the bytes skipped slice will not be copied, so make a copy if the return value is to be stored somewhere

func (*Iterator) SkipString

func (it *Iterator) SkipString() error

SkipString skips a string

func (*Iterator) Unmarshal

func (it *Iterator) Unmarshal(data []byte, obj interface{}) error

Unmarshal behave like standard json.Unmarshal

func (*Iterator) UnmarshalFromReader added in v0.0.3

func (it *Iterator) UnmarshalFromReader(r io.Reader, obj interface{}) error

UnmarshalFromReader behave like standard json.Unmarshal but with an io.Reader

func (*Iterator) Valid

func (it *Iterator) Valid(data []byte) bool

Valid behave like standard json.Valid

func (*Iterator) WrapError

func (it *Iterator) WrapError(err error) *DecodeError

WrapError wraps the error with the current iterator location

type Number

type Number = json.Number

Number alias of json.Number

type Streamer

type Streamer struct {
	Error error

	// TODO: 1. type of context?
	// TODO: 2. should context be reset as well?
	Context interface{} // custom stream context
	// contains filtered or unexported fields
}

Streamer is a chained class for encoding object to json

func NewStreamer

func NewStreamer() *Streamer

NewStreamer returns a new streamer

func (*Streamer) ArrayEnd

func (s *Streamer) ArrayEnd() *Streamer

ArrayEnd ends the array writing

func (*Streamer) ArrayStart

func (s *Streamer) ArrayStart() *Streamer

ArrayStart starts to write an array

func (*Streamer) Bool

func (s *Streamer) Bool(b bool) *Streamer

Bool writes a boolean value

func (*Streamer) EscapeHTML added in v0.0.5

func (s *Streamer) EscapeHTML(on bool)

EscapeHTML set if the string should be html-escaped

func (*Streamer) False

func (s *Streamer) False() *Streamer

False writes a `false`

func (*Streamer) Field

func (s *Streamer) Field(field string) *Streamer

Field writes an object field

func (*Streamer) Float32

func (s *Streamer) Float32(f float32) *Streamer

Float32 writes a float32 value

func (*Streamer) Float64

func (s *Streamer) Float64(f float64) *Streamer

Float64 writes a float64 value

func (*Streamer) Flush

func (s *Streamer) Flush() error

Flush flushes from buffer to the writer

func (*Streamer) Int

func (s *Streamer) Int(v int) *Streamer

Int writes an int value

func (*Streamer) Int16

func (s *Streamer) Int16(v int16) *Streamer

Int16 writes an int16 value

func (*Streamer) Int32

func (s *Streamer) Int32(v int32) *Streamer

Int32 writes an int32 value

func (*Streamer) Int64

func (s *Streamer) Int64(v int64) *Streamer

Int64 writes an int64 value

func (*Streamer) Int8

func (s *Streamer) Int8(v int8) *Streamer

Int8 writes an int8 value

func (*Streamer) Null

func (s *Streamer) Null() *Streamer

Null writes a `null`

func (*Streamer) ObjectEnd

func (s *Streamer) ObjectEnd() *Streamer

ObjectEnd ends the object writing

func (*Streamer) ObjectStart

func (s *Streamer) ObjectStart() *Streamer

ObjectStart starts to write an object

func (*Streamer) Raw

func (s *Streamer) Raw(raw []byte) *Streamer

Raw writes a raw object (in byte slice)

func (*Streamer) RawField

func (s *Streamer) RawField(b []byte) *Streamer

RawField writes an object field (in raw byte slice)

func (*Streamer) RawString

func (s *Streamer) RawString(raw string) *Streamer

RawString writes a raw object (in string)

func (*Streamer) Release added in v0.0.5

func (s *Streamer) Release()

Release the streamer, the streamer should not be used after call

func (*Streamer) Reset

func (s *Streamer) Reset(w io.Writer)

Reset resets the streamer with a new writer

func (*Streamer) String

func (s *Streamer) String(str string) *Streamer

func (*Streamer) True

func (s *Streamer) True() *Streamer

True writes a `true`

func (*Streamer) Uint

func (s *Streamer) Uint(v uint) *Streamer

Uint writes an uint value

func (*Streamer) Uint16

func (s *Streamer) Uint16(v uint16) *Streamer

Uint16 writes an uint16 value

func (*Streamer) Uint32

func (s *Streamer) Uint32(v uint32) *Streamer

Uint32 writes an uint32 value

func (*Streamer) Uint64

func (s *Streamer) Uint64(v uint64) *Streamer

Uint64 writes an uint64 value

func (*Streamer) Uint8

func (s *Streamer) Uint8(v uint8) *Streamer

Uint8 writes an uint8 value

func (*Streamer) Value

func (s *Streamer) Value(obj interface{}) *Streamer

Value encodes a golang object to json

type TypeNotSupportedError

type TypeNotSupportedError string

TypeNotSupportedError the decode target is not supported

func (TypeNotSupportedError) Error

func (e TypeNotSupportedError) Error() string

type UnexpectedByteError

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

UnexpectedByteError there is an unexpected character

func (UnexpectedByteError) Error

func (e UnexpectedByteError) Error() string

type UnknownFieldError

type UnknownFieldError string

UnknownFieldError there is an unknown field when decoding

func (UnknownFieldError) Error

func (e UnknownFieldError) Error() string

type ValDecoder

type ValDecoder interface {
	Decode(ptr unsafe.Pointer, it *Iterator, opts *DecOpts) error
}

ValDecoder is the interface to be implemented for custom decoder

type ValEncoder

type ValEncoder interface {
	IsEmpty(ptr unsafe.Pointer) bool

	Encode(ptr unsafe.Pointer, s *Streamer, opts *EncOpts)
}

ValEncoder is the interface to be implemented for custom encoder

type ValueType

type ValueType int

ValueType is the type of the next json token

const (
	// WhiteSpaceValue the next token is whitespace
	WhiteSpaceValue ValueType = iota
	// InvalidValue an error occurred
	InvalidValue
	// StringValue the next token is string
	StringValue
	// NumberValue the next token is number
	NumberValue
	// ObjectValue the next token is object
	ObjectValue
	// ArrayValue the next token is array
	ArrayValue
	// BoolValue the next token is a boolean value
	BoolValue
	// NullValue the next token is null
	NullValue
	// LastValue is a counter, should not be used
	LastValue
)

Source Files

Jump to

Keyboard shortcuts

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