jsondecoder

package
v0.0.0-...-9e9b692 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const PhasePanicMsg = "JSON decoder out of sync - data changing underfoot?"

PhasePanicMsg is used as a panic message when we end up with something that shouldn't happen. It can indicate a bug in the JSON decoder, or that something is editing the data slice while the decoder executes.

Variables

This section is empty.

Functions

func ParseBool

func ParseBool(b []byte) (bool, error)

func ParseFloat32

func ParseFloat32(b []byte) (float32, error)

func ParseFloat64

func ParseFloat64(b []byte) (float64, error)

func ParseInt32

func ParseInt32(b []byte) (int32, error)

func ParseInt64

func ParseInt64(b []byte) (int64, error)

func ParseUint32

func ParseUint32(b []byte) (uint32, error)

func ParseUint64

func ParseUint64(b []byte) (uint64, error)

func UnquoteBytes

func UnquoteBytes(s []byte) (t []byte, ok bool)

func UnquoteString

func UnquoteString(b []byte) (s string, ok bool)

UnquoteString converts a quoted JSON string literal s into an actual string t. The rules are different than for Go, so cannot use strconv.Unquote.

Types

type Decoder

type Decoder struct {
	OpCode OpCode // last read result
	// contains filtered or unexported fields
}

func New

func New(data []byte) (*Decoder, error)

func (*Decoder) ArrayAfterReadValue

func (d *Decoder) ArrayAfterReadValue() (stop bool)

func (*Decoder) ArrayBeforeReadValue

func (d *Decoder) ArrayBeforeReadValue() (stop bool)

func (*Decoder) ObjectAfterReadValue

func (d *Decoder) ObjectAfterReadValue() (stop bool)

func (*Decoder) ObjectBeforeReadKey

func (d *Decoder) ObjectBeforeReadKey() (stop bool)

func (*Decoder) ObjectBeforeReadValue

func (d *Decoder) ObjectBeforeReadValue()

func (*Decoder) ReadIndex

func (d *Decoder) ReadIndex() int

ReadIndex readIndex returns the position of the last byte read.

func (*Decoder) ReadItem

func (d *Decoder) ReadItem() []byte

ReadItem read current item value.

func (*Decoder) ReadObjectKey

func (d *Decoder) ReadObjectKey() string

ReadObjectKey Read key of object or map.

func (*Decoder) RescanLiteral

func (d *Decoder) RescanLiteral()

RescanLiteral is similar to scanWhile(ScanContinue), but it specialises the gojson case where we're decoding a literal. The decoder scans the input twice, once for syntax errors and to check the length of the value, and the second to perform the decoding.

Only in the second step do we use decodeState to tokenize literals, so we know there aren't any syntax errors. We can take advantage of that knowledge, and scan a literal's bytes much more quickly.

func (*Decoder) ScanError

func (d *Decoder) ScanError() error

func (*Decoder) ScanNext

func (d *Decoder) ScanNext()

ScanNext processes the byte at d.data[d.off].

func (*Decoder) ScanWhile

func (d *Decoder) ScanWhile(op OpCode)

ScanWhile scanWhile processes bytes in d.data[d.off:] until it receives a scan code not equal to op.

func (*Decoder) Skip

func (d *Decoder) Skip()

Skip skip scans to the end of what was started.

type InvalidUnmarshalError

type InvalidUnmarshalError struct {
	Type reflect.Type
}

An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)

func (*InvalidUnmarshalError) Error

func (e *InvalidUnmarshalError) Error() string

type OpCode

type OpCode int8
const (
	// Continue.
	ScanContinue     OpCode = iota // uninteresting byte
	ScanBeginLiteral               // end implied by next result != ScanContinue
	ScanBeginObject                // begin object
	ScanObjectKey                  // just finished object key (string)
	ScanObjectValue                // just finished non-last object value
	ScanEndObject                  // end object (implies ScanObjectValue if possible)
	ScanBeginArray                 // begin array
	ScanArrayValue                 // just finished array value
	ScanEndArray                   // end array (implies ScanArrayValue if possible)
	ScanSkipSpace                  // space byte; can skip; known to be last "continue" result

	// Stop.
	ScanEnd   // top-level value ended *before* this byte; known to be first "stop" result
	ScanError // hit an error, scanner.err.
)

These values are returned by the state transition functions assigned to scanner.state and the method scanner.eof. They give details about the current state of the scan that callers might be interested to know about. It is okay to ignore the return value of any particular call to scanner.state: if one call returns ScanError, every subsequent call will return ScanError too.

type ParsePhase

type ParsePhase int8

type SyntaxError

type SyntaxError struct {
	Offset int64 // error occurred after reading Offset bytes
	// contains filtered or unexported fields
}

A SyntaxError is a description of a JSON syntax error.

func (*SyntaxError) Error

func (e *SyntaxError) Error() string

type UnmarshalTypeError

type UnmarshalTypeError struct {
	Value  string       // description of JSON value - "bool", "array", "number -5"
	Type   reflect.Type // type of Go value it could not be assigned to
	Offset int64        // error occurred after reading Offset bytes
	Struct string       // name of the struct type containing the field
	Field  string       // the full path from root node to the field
}

An UnmarshalTypeError describes a JSON value that was not appropriate for a value of a specific Go type.

func (*UnmarshalTypeError) Error

func (e *UnmarshalTypeError) Error() string

Jump to

Keyboard shortcuts

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