Documentation ¶
Overview ¶
Package json contains a JSON lexer implementation.
It is expected that it is mostly used with generated parser code, so the interface is tuned for a parser that knows what kind of data is expected.
Index ¶
- type Lexer
- func (r *Lexer) AddError(e error)
- func (r *Lexer) AddNonFatalError(e error)
- func (r *Lexer) Bool() bool
- func (r *Lexer) Bytes() []byte
- func (r *Lexer) Consumed()
- func (r *Lexer) Delim(c byte)
- func (r *Lexer) Error() error
- func (r *Lexer) FetchToken()
- func (r *Lexer) Float32() float32
- func (r *Lexer) Float32Str() float32
- func (r *Lexer) Float64() float64
- func (r *Lexer) Float64Str() float64
- func (r *Lexer) GetNonFatalErrors() []*LexerError
- func (r *Lexer) GetPos() int
- func (r *Lexer) Int() int
- func (r *Lexer) Int16() int16
- func (r *Lexer) Int16Str() int16
- func (r *Lexer) Int32() int32
- func (r *Lexer) Int32Str() int32
- func (r *Lexer) Int64() int64
- func (r *Lexer) Int64Str() int64
- func (r *Lexer) Int8() int8
- func (r *Lexer) Int8Str() int8
- func (r *Lexer) IntStr() int
- func (r *Lexer) Interface() interface{}
- func (r *Lexer) IsDelim(c byte) bool
- func (r *Lexer) IsNull() bool
- func (r *Lexer) IsStart() bool
- func (r *Lexer) JsonNumber() json.Number
- func (r *Lexer) Null()
- func (r *Lexer) Ok() bool
- func (r *Lexer) Raw() []byte
- func (r *Lexer) Skip()
- func (r *Lexer) SkipRecursive()
- func (r *Lexer) String() string
- func (r *Lexer) Uint() uint
- func (r *Lexer) Uint16() uint16
- func (r *Lexer) Uint16Str() uint16
- func (r *Lexer) Uint32() uint32
- func (r *Lexer) Uint32Str() uint32
- func (r *Lexer) Uint64() uint64
- func (r *Lexer) Uint64Str() uint64
- func (r *Lexer) Uint8() uint8
- func (r *Lexer) Uint8Str() uint8
- func (r *Lexer) UintStr() uint
- func (r *Lexer) UintptrStr() uintptr
- func (r *Lexer) UnsafeBytes() []byte
- func (r *Lexer) UnsafeFieldName(skipUnescape bool) string
- func (r *Lexer) UnsafeString() string
- func (r *Lexer) WantColon()
- func (r *Lexer) WantComma()
- type LexerError
- type Reader
- func (r *Reader) Bool() bool
- func (r *Reader) Error() error
- func (r *Reader) FieldName() (string, error)
- func (r *Reader) Float32() float32
- func (r *Reader) Float64() float64
- func (r *Reader) Int16() int16
- func (r *Reader) Int32() int32
- func (r *Reader) Int64() int64
- func (r *Reader) Int8() int8
- func (r *Reader) IsError() bool
- func (r *Reader) String() string
- func (r *Reader) Uint16() uint16
- func (r *Reader) Uint32() uint32
- func (r *Reader) Uint64() uint64
- func (r *Reader) Uint8() uint8
- func (r *Reader) WantComma()
- type Writer
- func NewCompactWriterFloat32(b []byte, typ uint16, first float32) Writer
- func NewCompactWriterFloat64(b []byte, typ uint16, first float64) Writer
- func NewCompactWriterInt16(b []byte, typ uint16, first int16) Writer
- func NewCompactWriterInt32(b []byte, typ uint16, first int32) Writer
- func NewCompactWriterInt64(b []byte, typ uint16, first int64) Writer
- func NewCompactWriterInt8(b []byte, typ uint16, first int8) Writer
- func NewCompactWriterUint16(b []byte, typ uint16, first uint16) Writer
- func NewCompactWriterUint32(b []byte, typ uint16, first uint32) Writer
- func NewCompactWriterUint64(b []byte, typ uint16, first uint64) Writer
- func NewCompactWriterUint8(b []byte, typ uint16, first uint8) Writer
- func NewWriter(b []byte, typ uint16) Writer
- func (w *Writer) Base64Bytes(data []byte)
- func (w *Writer) Bool(v bool)
- func (w *Writer) BoolCompact(v bool) *Writer
- func (w *Writer) BoolField(n string, v bool)
- func (w *Writer) Finish() []byte
- func (w *Writer) Float32(n float32)
- func (w *Writer) Float32Compact(v float32) *Writer
- func (w *Writer) Float32Field(n string, v float32)
- func (w *Writer) Float32Str(n float32)
- func (w *Writer) Float64(n float64)
- func (w *Writer) Float64Compact(v float64) *Writer
- func (w *Writer) Float64Field(n string, v float64)
- func (w *Writer) Float64Str(n float64)
- func (w *Writer) Float64StrField(n string, v float64)
- func (w *Writer) Int(n int)
- func (w *Writer) Int16(n int16)
- func (w *Writer) Int16Compact(v int16) *Writer
- func (w *Writer) Int16Field(n string, v int16)
- func (w *Writer) Int16Str(n int16)
- func (w *Writer) Int32(n int32)
- func (w *Writer) Int32Compact(v int32) *Writer
- func (w *Writer) Int32Field(n string, v int32)
- func (w *Writer) Int32Str(n int32)
- func (w *Writer) Int64(n int64)
- func (w *Writer) Int64Compact(v int64) *Writer
- func (w *Writer) Int64Field(n string, v int64)
- func (w *Writer) Int64Str(n int64)
- func (w *Writer) Int8(n int8)
- func (w *Writer) Int8Compact(v int8) *Writer
- func (w *Writer) Int8Field(n string, v int8)
- func (w *Writer) Int8Str(n int8)
- func (w *Writer) IntCompact(v int) *Writer
- func (w *Writer) IntField(n string, v int)
- func (w *Writer) IntStr(n int)
- func (w *Writer) Raw(data []byte, err error)
- func (w *Writer) RawByte(c byte)
- func (w *Writer) RawString(s string)
- func (w *Writer) RawText(data []byte, err error)
- func (w *Writer) String(s string)
- func (w *Writer) StringCompact(v string) *Writer
- func (w *Writer) StringField(n string, v string)
- func (w *Writer) Uint(n uint)
- func (w *Writer) Uint16(n uint16)
- func (w *Writer) Uint16Compact(v uint16) *Writer
- func (w *Writer) Uint16Field(n string, v uint16)
- func (w *Writer) Uint16Str(n uint16)
- func (w *Writer) Uint32(n uint32)
- func (w *Writer) Uint32Compact(v uint32) *Writer
- func (w *Writer) Uint32Field(n string, v uint32)
- func (w *Writer) Uint32Str(n uint32)
- func (w *Writer) Uint64(n uint64)
- func (w *Writer) Uint64Compact(v uint64) *Writer
- func (w *Writer) Uint64Field(n string, v uint64)
- func (w *Writer) Uint64Str(n uint64)
- func (w *Writer) Uint8(n uint8)
- func (w *Writer) Uint8Compact(v uint8) *Writer
- func (w *Writer) Uint8Field(n string, v uint8)
- func (w *Writer) Uint8Str(n uint8)
- func (w *Writer) UintCompact(v uint) *Writer
- func (w *Writer) UintField(n string, v uint)
- func (w *Writer) UintStr(n uint)
- func (w *Writer) UintptrStr(n uintptr)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Lexer ¶
type Lexer struct { Data []byte // Input data given to the lexer. UseMultipleErrors bool // If we want to use multiple errors. FatalError error // Fatal error occurred during lexing. It is usually a syntax error. // contains filtered or unexported fields }
Lexer is a JSON lexer: it iterates over JSON tokens in a byte slice.
func (*Lexer) AddNonFatalError ¶
func (*Lexer) Consumed ¶
func (r *Lexer) Consumed()
Consumed reads all remaining bytes from the input, publishing an error if there is anything but whitespace remaining.
func (*Lexer) FetchToken ¶
func (r *Lexer) FetchToken()
FetchToken scans the input for the next token.
func (*Lexer) Float32Str ¶
func (*Lexer) Float64Str ¶
func (*Lexer) GetNonFatalErrors ¶
func (r *Lexer) GetNonFatalErrors() []*LexerError
func (*Lexer) Interface ¶
func (r *Lexer) Interface() interface{}
Interface fetches an interface{} analogous to the 'encoding/json' package.
func (*Lexer) IsDelim ¶
IsDelim returns true if there was no scanning error and next token is the given delimiter.
func (*Lexer) IsStart ¶
IsStart returns whether the lexer is positioned at the start of an input string.
func (*Lexer) JsonNumber ¶
JsonNumber fetches and json.Number from 'encoding/json' package. Both int, float or string, contains them are valid values
func (*Lexer) Null ¶
func (r *Lexer) Null()
Null verifies that the next token is null and consumes it.
func (*Lexer) SkipRecursive ¶
func (r *Lexer) SkipRecursive()
SkipRecursive skips next array or object completely, or just skips a single token if not an array/object.
Note: no syntax validation is performed on the skipped data.
func (*Lexer) UintptrStr ¶
func (*Lexer) UnsafeBytes ¶
UnsafeBytes returns the byte slice if the token is a string literal.
func (*Lexer) UnsafeFieldName ¶
UnsafeFieldName returns current member name string token
func (*Lexer) UnsafeString ¶
UnsafeString returns the string value if the token is a string literal.
Warning: returned string may point to the input buffer, so the string should not outlive the input buffer. Intended pattern of usage is as an argument to a switch statement.
type LexerError ¶
LexerError implements the error interface and represents all possible errors that can be generated during parsing the JSON data.
func (*LexerError) Error ¶
func (l *LexerError) Error() string
type Reader ¶
type Reader struct { Lexer Lexer Type uint16 First string OutOfOrder bool IsCompact bool NoFields bool }
func OpenReader ¶
type Writer ¶
func NewCompactWriterFloat32 ¶
func NewCompactWriterFloat64 ¶
func NewCompactWriterUint16 ¶
func NewCompactWriterUint32 ¶
func NewCompactWriterUint64 ¶
func (*Writer) Base64Bytes ¶
Base64Bytes appends data to the buffer after base64 encoding it
func (*Writer) BoolCompact ¶
func (*Writer) Float32Compact ¶
func (*Writer) Float32Field ¶
func (*Writer) Float32Str ¶
func (*Writer) Float64Compact ¶
func (*Writer) Float64Field ¶
func (*Writer) Float64Str ¶
func (*Writer) Float64StrField ¶
func (*Writer) Int16Compact ¶
func (*Writer) Int16Field ¶
func (*Writer) Int32Compact ¶
func (*Writer) Int32Field ¶
func (*Writer) Int64Compact ¶
func (*Writer) Int64Field ¶
func (*Writer) Int8Compact ¶
func (*Writer) IntCompact ¶
func (*Writer) Raw ¶
Raw appends raw binary data to the buffer or sets the error if it is given. Useful for calling with results of MarshalJSONTo-like functions.
func (*Writer) RawText ¶
RawText encloses raw binary data in quotes and appends in to the buffer. Useful for calling with results of MarshalText-like functions.