Documentation
¶
Index ¶
- Variables
- func AssignValue(src, dst reflect.Value) error
- func NewInput(data []byte) []byte
- func ReleaseRuntimeContext(ctx *RuntimeContext)
- func StreamOffsetBase(_, valueStart int64) int64
- func Valid(buf []byte) bool
- func ValidateEnd(buf []byte, cursor int64) error
- type BasePathNode
- type Decoder
- type Option
- type OptionFlags
- type Path
- type PathBuilder
- type PathIndexAllNode
- type PathIndexNode
- type PathNode
- type PathRecursiveNode
- type PathSelectorNode
- type PathString
- type QuotePathSelector
- type RuntimeContext
- func (ctx *RuntimeContext) DecoderOf(typ unsafe.Pointer) (Decoder, error)
- func (ctx *RuntimeContext) DiscardTypeError()
- func (ctx *RuntimeContext) HasTypeError() bool
- func (ctx *RuntimeContext) InputSyntaxError() error
- func (ctx *RuntimeContext) SetInput(data []byte) []byte
- func (ctx *RuntimeContext) TakeValue(typ reflect.Type, typeptr unsafe.Pointer) unsafe.Pointer
- func (ctx *RuntimeContext) TypeError(dec Decoder, typ reflect.Type, base, offsetBase int64) error
- type Stream
- func (s *Stream) Buffered() io.Reader
- func (s *Stream) Decode(dec Decoder, typ unsafe.Pointer, p unsafe.Pointer) error
- func (s *Stream) DecoderOf(typ unsafe.Pointer) (Decoder, error)
- func (s *Stream) InputOffset() int64
- func (s *Stream) More() bool
- func (s *Stream) Token() (any, error)
- func (s *Stream) TotalOffset() int64
Constants ¶
This section is empty.
Variables ¶
var (
EmptyInterfaceType = emptyInterfaceType
)
Functions ¶
func AssignValue ¶ added in v0.10.0
func NewInput ¶ added in v0.11.0
NewInput returns the buffer which the decoders decode: a copy of the input followed by a nul byte, which ends every scan.
func ReleaseRuntimeContext ¶
func ReleaseRuntimeContext(ctx *RuntimeContext)
func StreamOffsetBase ¶ added in v0.11.0
StreamOffsetBase returns the position which the offsets of the type errors of a value of a stream are relative to, of the end of the previous value and of the start of the value: encoding/json of Go 1.27 reports them from the start of the value.
func Valid ¶ added in v0.11.0
Valid reports whether buf, the input followed by the nul byte, is a JSON value, by the grammar which the values which are not decoded are skipped by.
func ValidateEnd ¶ added in v0.11.0
ValidateEnd returns the syntax error of what follows the value which ends at cursor in buf, the input followed by the nul byte: white spaces only may follow it, up to the end of the input. A nul byte in the input is a byte which the grammar doesn't have there, as encoding/json has it.
Types ¶
type BasePathNode ¶ added in v0.10.0
type BasePathNode struct {
// contains filtered or unexported fields
}
type Decoder ¶
type Decoder interface {
Decode(*RuntimeContext, int64, int64, unsafe.Pointer) (int64, error)
DecodePath(*RuntimeContext, int64, int64) ([][]byte, int64, error)
}
func CompileToGetDecoder ¶
CompileToGetDecoder returns the decoder of the type. The type is given by the pointer to its type descriptor, which the caller reads from an interface value, because reflect.Type is required only when the decoder is not cached yet.
func NewPathDecoder ¶ added in v0.10.0
func NewPathDecoder() Decoder
type OptionFlags ¶
type OptionFlags uint8
const ( FirstWinOption OptionFlags = 1 << iota ContextOption PathOption // UseNumberOption decodes a number into interface{} as json.Number instead of float64. UseNumberOption // DisallowUnknownFieldsOption makes an object key which matches no field of the struct an error. DisallowUnknownFieldsOption // NoCopyStringOption makes the decoded strings refer to the input instead of a copy of their bytes. NoCopyStringOption )
type Path ¶ added in v0.10.0
type PathBuilder ¶ added in v0.10.0
type PathBuilder struct {
// contains filtered or unexported fields
}
type PathIndexAllNode ¶ added in v0.10.0
type PathIndexAllNode struct {
*BasePathNode
}
func (*PathIndexAllNode) Field ¶ added in v0.10.0
func (n *PathIndexAllNode) Field(fieldName string) (PathNode, bool, error)
func (*PathIndexAllNode) Get ¶ added in v0.10.0
func (n *PathIndexAllNode) Get(src, dst reflect.Value) error
func (*PathIndexAllNode) Index ¶ added in v0.10.0
func (n *PathIndexAllNode) Index(idx int) (PathNode, bool, error)
func (*PathIndexAllNode) String ¶ added in v0.10.0
func (n *PathIndexAllNode) String() string
type PathIndexNode ¶ added in v0.10.0
type PathIndexNode struct {
*BasePathNode
// contains filtered or unexported fields
}
func (*PathIndexNode) Field ¶ added in v0.10.0
func (n *PathIndexNode) Field(fieldName string) (PathNode, bool, error)
func (*PathIndexNode) Get ¶ added in v0.10.0
func (n *PathIndexNode) Get(src, dst reflect.Value) error
func (*PathIndexNode) Index ¶ added in v0.10.0
func (n *PathIndexNode) Index(idx int) (PathNode, bool, error)
func (*PathIndexNode) String ¶ added in v0.10.0
func (n *PathIndexNode) String() string
type PathRecursiveNode ¶ added in v0.10.0
type PathRecursiveNode struct {
*BasePathNode
// contains filtered or unexported fields
}
func (*PathRecursiveNode) Field ¶ added in v0.10.0
func (n *PathRecursiveNode) Field(fieldName string) (PathNode, bool, error)
func (*PathRecursiveNode) Get ¶ added in v0.10.0
func (n *PathRecursiveNode) Get(src, dst reflect.Value) error
func (*PathRecursiveNode) Index ¶ added in v0.10.0
func (n *PathRecursiveNode) Index(_ int) (PathNode, bool, error)
func (*PathRecursiveNode) String ¶ added in v0.10.0
func (n *PathRecursiveNode) String() string
type PathSelectorNode ¶ added in v0.10.0
type PathSelectorNode struct {
*BasePathNode
// contains filtered or unexported fields
}
func (*PathSelectorNode) Field ¶ added in v0.10.0
func (n *PathSelectorNode) Field(fieldName string) (PathNode, bool, error)
func (*PathSelectorNode) Get ¶ added in v0.10.0
func (n *PathSelectorNode) Get(src, dst reflect.Value) error
func (*PathSelectorNode) Index ¶ added in v0.10.0
func (n *PathSelectorNode) Index(idx int) (PathNode, bool, error)
func (*PathSelectorNode) String ¶ added in v0.10.0
func (n *PathSelectorNode) String() string
type PathString ¶ added in v0.10.0
type PathString string
func (PathString) Build ¶ added in v0.10.0
func (s PathString) Build() (*Path, error)
type QuotePathSelector ¶ added in v0.10.0
type QuotePathSelector int
const ( SingleQuotePathSelector QuotePathSelector = 1 DoubleQuotePathSelector QuotePathSelector = 2 )
type RuntimeContext ¶
func TakeRuntimeContext ¶
func TakeRuntimeContext() *RuntimeContext
func (*RuntimeContext) DecoderOf ¶ added in v0.11.0
func (ctx *RuntimeContext) DecoderOf(typ unsafe.Pointer) (Decoder, error)
DecoderOf returns the decoder of the type, compiling it if the type is new.
A runtime context remembers the decoders of the types it decoded last: the same types are decoded again and again in most of the programs, and this is cheaper than a lookup of the table shared by every goroutine. The first entry of the set is looked at here, which is inlined into the callers; the rest in lookupDecoder.
func (*RuntimeContext) DiscardTypeError ¶ added in v0.11.0
func (ctx *RuntimeContext) DiscardTypeError()
DiscardTypeError drops the type error of a decoding which failed with another error.
func (*RuntimeContext) HasTypeError ¶ added in v0.11.0
func (ctx *RuntimeContext) HasTypeError() bool
HasTypeError reports whether the decoding has a type error, which TypeError returns: the type of the value is made for it only.
func (*RuntimeContext) InputSyntaxError ¶ added in v0.11.0
func (ctx *RuntimeContext) InputSyntaxError() error
InputSyntaxError returns the first syntax error of the input of the decoding, as encoding/json reports it, or nil if the input is valid: the decoders report a syntax error as they meet it, which this reports again as encoding/json does, which checks the whole input first. The input is copied again, since the decoding writes its buffer, as the escapes of the keys are decoded in it.
func (*RuntimeContext) SetInput ¶ added in v0.11.0
func (ctx *RuntimeContext) SetInput(data []byte) []byte
SetInput copies data to the buffer of the context, followed by a nul byte which ends every scan, and makes it the buffer to decode.
func (*RuntimeContext) TakeValue ¶ added in v0.11.0
TakeValue returns the address of a zero value of typ in the heap, which the context keeps for the next call with the same type. typ is given as its type descriptor too, which is how it is looked up.
type Stream ¶
type Stream struct {
Option *Option
// contains filtered or unexported fields
}
Stream reads the values of a JSON text from an io.Reader one by one.
A value is decoded by the same decoders as a byte slice is: the stream reads until its buffer holds the whole value ( scanValue ), puts a nul byte after the value and lets the decoder work on the buffer. The decoded strings refer to the buffer, so a byte which has been read is never overwritten: when the buffer is full, the bytes which are not consumed yet are copied to a new one.
func (*Stream) Buffered ¶
Buffered returns a reader of the data read from the reader but not consumed yet.
func (*Stream) Decode ¶ added in v0.11.0
Decode decodes the next value of the stream into p, of the pointer type typ, by dec. If the value has a type error, the stream goes on after the value, as the one of encoding/json does.
func (*Stream) DecoderOf ¶ added in v0.11.0
DecoderOf returns the decoder of the type, from the recent decoders of the context of the stream.
func (*Stream) InputOffset ¶ added in v0.11.0
InputOffset returns the offset of the stream which Decoder.InputOffset reports: the end of the last token or value read, or where a read which failed started.
func (*Stream) More ¶
More reports whether the current array or object has another element: at the end of the input in one, it reports true, and the error of the end is returned by the next read, as encoding/json of Go 1.27 does.
func (*Stream) Token ¶
Token returns the next token of the stream: a delimiter, a string, a number, a bool or nil. The commas and the colons are consumed where the grammar has them.
func (*Stream) TotalOffset ¶
TotalOffset returns the number of the bytes consumed from the reader.
Source Files
¶
- anonymous_field.go
- array.go
- assign.go
- bool.go
- bytes.go
- compile.go
- context.go
- float.go
- func.go
- int.go
- interface.go
- invalid.go
- map.go
- number.go
- number_parse.go
- option.go
- path.go
- pow10.go
- pow10_table.go
- ptr.go
- reflect.go
- scan.go
- scan_amd64.go
- skip.go
- slice.go
- stream.go
- stream_token.go
- stream_token_v2.go
- string.go
- string_scan_amd64.go
- string_unescape.go
- struct.go
- struct_keys.go
- syntax_error.go
- syntax_error_v2.go
- type.go
- type_error.go
- type_error_embedded.go
- type_error_v2.go
- uint.go
- unmarshal_json.go
- unmarshal_text.go
- wrapped_string.go