Help us shape the future of Go! Take the 2026 Go Developer Survey

decoder

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EmptyInterfaceType = emptyInterfaceType
)
View Source
var ErrUseDefault = errors.New("json: the value is decoded by the next representation")

ErrUseDefault is the error of a method or a function of unmarshaling which declined a value without reading it: the next function, or the next method or the kind of the type, decodes it.

View Source
var V2Hooks struct {
	// UnmarshalerFromType is the type of the interface json.UnmarshalerFrom.
	UnmarshalerFromType reflect.Type
	// UnmarshalFrom decodes the value at cursor into the value at p, of typ, by its UnmarshalJSONFrom: it returns
	// the cursor after the value, or ErrUseDefault if the method declined the value.
	UnmarshalFrom func(ctx *RuntimeContext, cursor, depth int64, typ reflect.Type, p unsafe.Pointer) (int64, error)
	// SkipStreamValue skips the value of the stream, nested in depth objects and arrays, which the buffer doesn't
	// hold whole, by a jsontext.Decoder attached at its place ( see V2Call.Value ), which checks it as
	// encoding/json/v2 checks a value it skips: it returns the error at its place.
	SkipStreamValue func(s *Stream, depth int64) error
	// Lend sets up the stream of the call of UnmarshalDecode of ctx, which decodes its value in the buffer of its
	// decoder without it ( see V2Call.Lent ), as the stream is while it decodes the value whole ( see
	// Stream.decodeWholeV2 ): for a method or a function of the value which reads a jsontext.Decoder, attached at
	// its place, or for its error.
	Lend func(ctx *RuntimeContext)
	// AppendUnquote is jsontext.AppendUnquote, which reads a JSON string in a JSON string of the `string` option with
	// StringifyWithLegacySemantics, and whose error is the one of the value.
	AppendUnquote func(dst []byte, src string) ([]byte, error)
}

V2Hooks are what the decoder needs of the v2 json package, which it can't import: the decoding by the methods which read a jsontext.Decoder, which the package sets.

Functions

func AssignValue added in v0.10.0

func AssignValue(src, dst reflect.Value) error

AssignValue sets src, cast to the type which dst points to, to the value dst points to. dst must be a pointer which is not nil. The value is not changed when src cannot be cast.

func DecodeWholeInV2 added in v0.12.0

func DecodeWholeInV2(ctx *RuntimeContext, buf []byte, cursor, end, depth int64, dec Decoder, p unsafe.Pointer) (int64, error)

DecodeWholeInV2 decodes the value of buf from cursor up to end, which buf holds whole, by dec into p, as decodeWholeV2 decodes the value of a stream which the buffer holds whole: nested in depth objects and arrays, in buf, whose byte at end is nul while the value is decoded. A type error which a decoder of v1 recorded is the error of the value, and the names of the objects of the value which an error ended are dropped after it, as DecodeV2After drops them.

func IsArrayLengthError added in v0.12.0

func IsArrayLengthError(err error) bool

IsArrayLengthError reports whether err is the error of the length of a JSON array decoded into a Go array, which is at the end of the JSON array.

func IsV2Bytes added in v0.12.0

func IsV2Bytes(typ reflect.Type, flags V2Flags) bool

IsV2Bytes reports whether typ, a slice or an array, is of bytes for the options flags, whose value is a base64 string: a []byte or a [N]byte, but a [N]byte with FormatByteArrayAsArray, and a slice or an array of a named byte type with FormatBytesWithLegacySemantics, which is otherwise a JSON array of its values.

func NewInput added in v0.11.0

func NewInput(data []byte) []byte

NewInput returns the buffer which the decoders decode: a copy of the input followed by a nul byte, which ends every scan.

func ReadsJSONText added in v0.12.0

func ReadsJSONText(dec Decoder) bool

ReadsJSONText reports whether dec is the decoder of a method or a function which reads a jsontext.Decoder, which may read on past its value, or of a pointer, whose value may be one: decodeTopV2 decodes them by decodeNestedV2.

func ReleaseRuntimeContext

func ReleaseRuntimeContext(ctx *RuntimeContext)

func ReleaseStreamV2 added in v0.12.0

func ReleaseStreamV2(s *Stream)

ReleaseStreamV2 puts the stream back, without its reader and the state of its call ( see EndV2 ).

func SetBuf added in v0.12.0

func SetBuf(ctx *RuntimeContext, buf []byte)

SetBuf makes buf, an input followed by a nul byte which the caller keeps, the input of the decoding of ctx, whose strings are copied out of it, as they are out of an input of SetInput. A nil buf drops it. It is a function, not a method: a method of the context moves the data of the binary ( its method table ), which slows its decoding.

func SetV2Flags added in v0.12.0

func SetV2Flags(ctx *RuntimeContext, flags V2Flags)

SetV2Flags sets the options of v2 of ctx for a decoding, which every setting of them before a decoding is made by, as the others clear them after one: the recent decoders are emptied if they were compiled for other options of encoding/json which change the decoders, which their keys have no room for ( see recentV1Options ), once for the call rather than in every DecoderOfV2, by a call of its own, so that SetV2Flags is inlined into the callers.

func Valid added in v0.11.0

func Valid(buf []byte) bool

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

func ValidateEnd(buf []byte, cursor int64) error

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.

func WholeEndV2 added in v0.12.0

func WholeEndV2(buf []byte, cursor, length int64) (int64, bool)

WholeEndV2 returns the end of the object or the array at cursor of buf, which has the input up to length, followed by the room of a decoder ( see textcoder.InputRoom ), and reports whether it ends there: false for any other value.

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

func CompileToGetDecoder(typ unsafe.Pointer) (Decoder, error)

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 CompileToGetDecoderV2 added in v0.12.0

func CompileToGetDecoderV2(typ unsafe.Pointer, flags V2Flags) (Decoder, error)

CompileToGetDecoderV2 returns the decoder of the type for the semantics of encoding/json/v2 and the options flags, of which StringifyNumbers and the ones of v1DecoderOptions change the decoders, compiling it if the type is new.

func NewPathDecoder added in v0.10.0

func NewPathDecoder() Decoder

type Option

type Option struct {
	Flags OptionFlags
	// V2 is in the room which Flags leaves before Context on 64-bit platforms, so that Option keeps its size there.
	V2      V2Flags
	Context context.Context
	Path    *Path
}

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 Path struct {
	RootSelectorOnly        bool
	SingleQuotePathSelector bool
	DoubleQuotePathSelector bool
	// contains filtered or unexported fields
}

func (*Path) Field added in v0.10.0

func (p *Path) Field(sel string) (PathNode, bool, error)

func (*Path) Get added in v0.10.0

func (p *Path) Get(src, dst reflect.Value) error

func (*Path) String added in v0.10.0

func (p *Path) String() string

type PathBuilder added in v0.10.0

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

func (*PathBuilder) Build added in v0.10.0

func (b *PathBuilder) Build(buf []rune) (*Path, error)

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 PathNode added in v0.10.0

type PathNode interface {
	fmt.Stringer
	Index(idx int) (PathNode, bool, error)
	Field(fieldName string) (PathNode, bool, error)
	Get(src, dst reflect.Value) error
	// contains filtered or unexported methods
}

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

Get assigns to dst a slice of the values which the name of n has at any depth of src, in the members of objects and the elements of arrays, with the rest of the path applied to each of them: a value in which the rest finds nothing adds nothing.

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

type RuntimeContext struct {
	Buf    []byte
	Option *Option
	// contains filtered or unexported fields
}

func TakeRuntimeContext

func TakeRuntimeContext() *RuntimeContext

func (*RuntimeContext) CurrentV2Call added in v0.12.0

func (ctx *RuntimeContext) CurrentV2Call() *V2Call

CurrentV2Call returns the state of the call of the v2 json package which decodes by ctx, which the call made by V2Call, so it is never nil.

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; the rest in lookupDecoder.

func (*RuntimeContext) DecoderOfV2 added in v0.12.0

func (ctx *RuntimeContext) DecoderOfV2(typ unsafe.Pointer) (Decoder, error)

DecoderOfV2 returns the decoder of the semantics of encoding/json/v2 of the type, for the options and the functions of unmarshaling of ctx. The decoder of a call without functions is remembered with the decoders of the context as v1's DecoderOf remembers them, under the address of the type with the marks of the decoders of v2. A decoder in neither entry of its set is the one of the shared table, which takes the first entry, and the one decoded before it the second.

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) ReadValue added in v0.12.0

func (ctx *RuntimeContext) ReadValue(cursor, depth int64, typ reflect.Type, method errors.UnmarshalMethod) (int64, int64, error)

ReadValue reads the value at cursor whole, as the method of unmarshaling, or the function, of a value of typ is given it: it must have the text which v2 allows ( see skipValueV2 ). It returns the start and the end of the value. An error of the text is one of the value, at its start, which the v2 json package reads whole to find it again, as encoding/json/v2 reads it.

func (*RuntimeContext) RecordV1Error added in v0.12.0

func (ctx *RuntimeContext) RecordV1Error(err error) bool

RecordV1Error records err, an error of the decoding of a value with ReportErrorsWithLegacySemantics, as the type error of encoding/json, if it is the first one, and reports whether the decoding goes on after it: the error of a value which encoding/json/v2 reports as its SemanticError doesn't stop it, but a syntax error, an error of the reader, a name which another member has, and a syntax error or an error of the reader which a method or a function returned, do, as encoding/json stops at them.

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) SetPath added in v0.12.0

func (ctx *RuntimeContext) SetPath(p *Path)

SetPath makes the decoding select the values of p. It selects by a copy of p, as it moves the node of the path it is at: p stays as it is for the next call, after one which fails too, and for the calls which other goroutines make at the same time.

func (*RuntimeContext) TakeValue added in v0.11.0

func (ctx *RuntimeContext) TakeValue(typ reflect.Type, typeptr unsafe.Pointer) unsafe.Pointer

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.

func (*RuntimeContext) TypeError added in v0.11.0

func (ctx *RuntimeContext) TypeError(typ reflect.Type, base, offsetBase int64, outer []string) error

TypeError returns the first type error of the decoding of the value at base into a value of typ, or nil if the decoding had none. Its offset is relative to offsetBase. outer are the steps of the path to the value in the values which it is in, which a decoder of jsontext read it in, unescaped, or nil.

func (*RuntimeContext) V2Call added in v0.12.0

func (ctx *RuntimeContext) V2Call() *V2Call

V2Call returns the state of the call of the v2 json package which decodes by ctx, which it makes the first time.

func (*RuntimeContext) V2TypeError added in v0.12.0

func (ctx *RuntimeContext) V2TypeError() error

V2TypeError returns the type error which a decoder of v1 recorded, as the error of v2 ( see v2Error ), or nil if none did.

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: a value which the buffer holds whole is decoded from it, with a nul byte put after the value, and an object or an array which it doesn't is decoded element by element as it is read ( see scanFailed ), so that the buffer keeps its size. The decoded strings are copied out of the buffer, so that a value keeps alive no memory but its own, and the buffer is reused in place when it is full: the bytes which are not consumed yet are moved to its start. Under NoCopyStringOption, the strings refer to the buffer, which is then never written again: the bytes are copied to a new one instead ( see referred ).

func NewStream

func NewStream(r io.Reader) *Stream

func NewStreamV2 added in v0.12.0

func NewStreamV2() *Stream

NewStreamV2 returns a new stream for the decodings of v2, which a pool keeps: its context has the decoders of the types decoded last, as a context of the pool of the contexts has them ( see RuntimeContext.recentDecoders ).

func TakeStreamV2 added in v0.12.0

func TakeStreamV2(r io.Reader) *Stream

TakeStreamV2 returns a stream which reads r, for a decoding of v2 by the state of the call of its context ( see RuntimeContext.V2Call ), whose path is the top level.

func (*Stream) AfterTopLevel added in v0.12.0

func (s *Stream) AfterTopLevel() (bool, error)

AfterTopLevel moves the stream to the end of the input after its top-level value, which only white space may follow, and reports whether it is there: if not, the place of the byte after the value is recorded ( see V2Call.Place ). It returns the error of the reader.

func (*Stream) BeginV2 added in v0.12.0

func (s *Stream) BeginV2(r io.Reader)

BeginV2 makes the stream, which has no reader ( see EndV2 ), read r, for a decoding of v2 by the state of the call of its context, whose path is the top level.

func (*Stream) BeginV2At added in v0.12.0

func (s *Stream) BeginV2At(r io.Reader, levels []textcoder.Level) []textcoder.Level

BeginV2At is BeginV2 for a value at the place levels, whose names are its own, which are made the path of the call of the stream, without a copy ( see SetPath ). It returns the path the call had, whose arrays the caller keeps for its next levels.

func (*Stream) BorrowV2 added in v0.12.0

func (s *Stream) BorrowV2(dec unsafe.Pointer, from int64) bool

BorrowV2 makes the stream, which BeginV2 or BeginV2At began, read the input of dec, a jsontext.Decoder, from the offset from of the whole input, in the buffer of dec, in place, and read more into it through dec, initBufSize bytes at most at a time, as it reads its reader ( see readSource ): the bytes are not copied into its own buffer. It reports false, having done nothing, if the buffer can't be read so ( see textcoder.DecoderBuffer ). Once a decoder attached at a value reads on, the stream holds what it needs of the buffer in its own, and reads its reader ( see ReadOn ).

func (*Stream) Buffered

func (s *Stream) Buffered() io.Reader

Buffered returns a reader of the data read from the reader but not consumed yet.

func (*Stream) Context added in v0.12.0

func (s *Stream) Context() *RuntimeContext

Context returns the context of the stream, which its values are decoded by.

func (*Stream) Decode added in v0.11.0

func (s *Stream) Decode(dec Decoder, typ unsafe.Pointer, p unsafe.Pointer) error

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) DecodeLongV2After added in v0.12.0

func (s *Stream) DecodeLongV2After(dec Decoder, p unsafe.Pointer, depth, from, start int64) error

DecodeLongV2After is DecodeV2After for an object or an array at the offset start of what has been read, which the caller found not whole in it ( see WholeEndV2 ), by dec, which is not the decoder of a method, a function or a pointer ( see ReadsJSONText ): it is decoded element by element at once, as decodeTopV2 decodes it after its scan.

func (*Stream) DecodeV2 added in v0.12.0

func (s *Stream) DecodeV2(dec Decoder, p unsafe.Pointer, depth int64) error

DecodeV2 decodes the next value of the stream by dec, a decoder of v2, into p: whole if the buffer holds it, and else element by element. The value is nested in depth objects and arrays, the ones of the path but the top level. It returns the error of the reader, io.EOF at the end of the input, if no value is left, and the error of the decoding, whose place is recorded ( see V2Call.Place ) unless it is an error of encoding/json/v2 at its place.

func (*Stream) DecodeV2After added in v0.12.0

func (s *Stream) DecodeV2After(dec Decoder, p unsafe.Pointer, depth, from, start int64) error

DecodeV2After is DecodeV2 for a value at the offset start of the input, after from, the offset of the end of the token before it, which the stream reads from: the white space and the delimiter between them, which were checked, are skipped. It never returns io.EOF.

func (*Stream) DecoderOf added in v0.11.0

func (s *Stream) DecoderOf(typ unsafe.Pointer) (Decoder, error)

DecoderOf returns the decoder of the type, from the recent decoders of the context of the stream.

func (*Stream) Drop added in v0.12.0

func (s *Stream) Drop()

Drop empties the buffer of the stream, which a decoder attached at its value read on from and failed after: the stream has nothing to give back ( see Read ), as the decoding of the value fails.

func (*Stream) EndV2 added in v0.12.0

func (s *Stream) EndV2()

EndV2 drops the reader of the stream and the state of its call, which may then read another reader ( see BeginV2 ).

func (*Stream) InputOffset added in v0.11.0

func (s *Stream) InputOffset() int64

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) LendAt added in v0.12.0

func (s *Stream) LendAt(from, start int64)

LendAt makes the stream, which BorrowV2 made read the buffer of a jsontext.Decoder from the offset from, the end of the token before its next value, at that value, at the offset start, as decodeWholeV2 is while it decodes it: for a value which the caller decodes whole in the buffer ( see V2Hooks.Lend ).

func (*Stream) More

func (s *Stream) More() bool

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) Offset added in v0.12.0

func (s *Stream) Offset() int64

Offset returns the offset in the input of the cursor of the stream.

func (*Stream) PlaceWholeV2 added in v0.12.0

func (s *Stream) PlaceWholeV2(err error, from, end int64) error

PlaceWholeV2 records the place of err, the error of the value at the cursor, which the caller decoded whole in the buffer up to end ( see DecodeWholeInV2 ), after from, the total offset of the end of the token before it, as decodeWholeV2 records it. It returns err.

func (*Stream) Read added in v0.12.0

func (s *Stream) Read() ([]byte, int64)

Read returns what has been read and not dropped, and the offset of its first byte in the input.

func (*Stream) ReadAllV2 added in v0.12.0

func (s *Stream) ReadAllV2() ([]byte, error)

ReadAllV2 returns the whole input of the stream, which has read nothing yet, up to the end of its reader, followed by a nul byte and the padding which the decoders may read after it ( see SetInput ), or the error of the reader if it fails.

func (*Stream) ReadError added in v0.12.0

func (s *Stream) ReadError() error

ReadError returns the error of the reader, which the stream reports at the end of what it read, or nil if the reader reached the end of the input, or has not failed.

func (*Stream) ReadOn added in v0.12.0

func (s *Stream) ReadOn(p []byte) (int, error)

ReadOn reads more of the input into p, for a decoder attached at the value of the stream ( see V2Call.Value ): initBufSize bytes at most, as the stream reads, and the error of the reader is kept, as the stream keeps it.

func (*Stream) ReadsInPlace added in v0.12.0

func (s *Stream) ReadsInPlace() bool

ReadsInPlace reports whether the stream reads the buffer of a jsontext.Decoder in place ( see BorrowV2 ), which what it has read is then: it has not left it for its own buffer ( see leaveSource ).

func (*Stream) RestorePath added in v0.12.0

func (s *Stream) RestorePath(saved []textcoder.Level) []textcoder.Level

RestorePath sets the path of the call of the stream back to saved, which SetPath returned, and returns the path which it set, whose arrays the caller keeps for the next SetPath.

func (*Stream) Resume added in v0.12.0

func (s *Stream) Resume(end int64, rest []byte)

Resume makes the stream go on at the offset end of the input, where a decoder attached at its value stopped: in the buffer, or, if the decoder read on, before rest, what it read and didn't use, which the buffer takes.

func (*Stream) SetPath added in v0.12.0

func (s *Stream) SetPath(path, levels []textcoder.Level) []textcoder.Level

SetPath sets the path of the call of the stream to levels, the place of the next value which it decodes, copied into path, whose arrays it reuses, and returns the path it had, which the caller sets back by RestorePath.

func (*Stream) StartAt added in v0.12.0

func (s *Stream) StartAt(offset int64)

StartAt makes the stream, which has read nothing, start at the offset of the input, which its reader reads from.

func (*Stream) Token

func (s *Stream) Token() (any, error)

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

func (s *Stream) TotalOffset() int64

TotalOffset returns the number of the bytes consumed from the reader.

func (*Stream) Unread added in v0.12.0

func (s *Stream) Unread() []byte

Unread returns the bytes of the buffer which the stream read after its cursor.

func (*Stream) ViewV2 added in v0.12.0

func (s *Stream) ViewV2(in []byte, base int64)

ViewV2 makes the stream, which BeginV2At began, read in place in, a whole input, which has a nul byte after it, from the offset base of the whole input: it reads nothing more, and its buffer is its own again after EndV2. A caller which decodes a value of in whole, as decodeWholeV2 decodes the value of a stream, sets the stream at the value ( see LendAt ), so that a method or a function of the value finds its place by the stream.

type StreamPlace added in v0.12.0

type StreamPlace struct {
	From, End int64
	Set       bool
}

StreamPlace is the part of the buffer of a stream where an error of its decoding of v2 is found again: from From, the end of the token before the member, the element or the value which failed, in the innermost level of the path, up to End ( see V2Call.Path ).

type StreamValue added in v0.12.0

type StreamValue struct {
	From, Start int64
	ReadsOn     bool
}

StreamValue is the value of a stream which a decoder of v2 decodes, in the innermost level of the path, for a method or a function which reads a jsontext.Decoder, which is attached at its place: From and Start are the offsets in the buffer of the end of the token before the value and of the value. ReadsOn is set for a value which the buffer doesn't hold whole, which the decoder reads on from the reader of the stream ( see Stream.ReadOn ).

type UnmarshalFunc added in v0.12.0

type UnmarshalFunc struct {
	Type reflect.Type
	// Decode decodes the value at cursor into the value at p, of the type from, and returns the cursor after it, or
	// ErrUseDefault if the function declined the value, which a function of UnmarshalFromFunc may.
	Decode func(ctx *RuntimeContext, cursor, depth int64, p unsafe.Pointer, from reflect.Type) (int64, error)
	// FromDecoder is set for a function of UnmarshalFromFunc, which reads a jsontext.Decoder: a stream gives it a
	// value which it hasn't read whole ( see V2Call.Attach ), and any other function the value read whole.
	FromDecoder bool
}

UnmarshalFunc is a function of unmarshaling, for the values of the types castable to Type ( see runtime.CastableTo ).

type UnmarshalFuncs added in v0.12.0

type UnmarshalFuncs struct {
	Funcs []UnmarshalFunc
	// contains filtered or unexported fields
}

UnmarshalFuncs are the functions of unmarshaling of a call, in the order they are tried, with the decoders compiled for them.

type V2Call added in v0.12.0

type V2Call struct {
	// Funcs are the functions of unmarshaling of the call, which the decoders are compiled for ( see
	// DecoderOfV2 ), or nil.
	Funcs *UnmarshalFuncs
	// Config are the options of the call, which a method or a function of unmarshaling which reads a
	// jsontext.Decoder is given.
	Config *options.Config
	// Options are the options of a call of Unmarshal or of UnmarshalRead which has options, which Config points to:
	// the context, which a pool keeps, holds them for its calls.
	Options options.Config
	// From is the state of the v2 json package for the methods and the functions which read a jsontext.Decoder,
	// which the decoder doesn't know.
	From unsafe.Pointer
	// Stream is the stream which the call decodes, or nil for an input of its own, with the state of its decoding
	// element by element ( see Stream.DecodeV2 ): Path is the place of the value which is decoded, a level for
	// each object and array which it is in, the top level first ( see textcoder.Level ), and Value the value of
	// the innermost level which a decoder of v2 decodes.
	Stream *Stream
	Path   []textcoder.Level
	Value  StreamValue

	// Place is where the error which the decoding of the stream returned is found again ( see StreamPlace ).
	Place StreamPlace

	// Lent is the call of UnmarshalDecode which decodes the value of the call in the buffer of its decoder, without
	// the stream, which it sets up for a method or a function which reads a jsontext.Decoder ( see V2Hooks.Lend ),
	// or nil.
	Lent unsafe.Pointer
	// contains filtered or unexported fields
}

V2Call is the state of a call of the v2 json package which its decoders read, which a context keeps from a call to the next once a call made it ( see RuntimeContext.V2Call ).

type V2Flags added in v0.12.0

type V2Flags uint32

V2Flags are the options of a decoding by the semantics of encoding/json/v2, which the v2 json package decodes by ( see CompileToGetDecoderV2 ). They are zero for the decodings of v1.

const (
	// V2Semantics is set for every decoding of v2.
	V2Semantics V2Flags = 1 << iota
	// V2AllowInvalidUTF8 lets the strings have invalid UTF-8, which is replaced by U+FFFD.
	V2AllowInvalidUTF8
	// V2AllowDuplicateNames lets an object have a name more than once.
	V2AllowDuplicateNames
	// V2StringifyNumbers decodes the numbers of the numeric types from JSON strings, by decoders of their own.
	V2StringifyNumbers
	// V2MatchCaseInsensitiveNames matches the names of an object with the names of the fields of a struct by their
	// folded names too, unless a field has the `case:strict` option.
	V2MatchCaseInsensitiveNames
	// V2RejectUnknownMembers makes a name of an object which is the name of no field of a struct an error, unless
	// the struct has an embedded fallback.
	V2RejectUnknownMembers
	// The options of the semantics of encoding/json which the v2 json package applies when unmarshaling, named by the
	// options of the root package, whose documentation they follow, in the order of their properties in
	// internal/options, from ParseBytesWithLooseRFC4648, so that they are copied at once ( see unmarshalFlags of the
	// v2 json package ).
	V2ParseBytesWithLooseRFC4648
	V2ParseTimeWithLooseRFC3339
	V2UnmarshalArrayFromAnyLength
	V2MergeWithLegacySemantics
	V2MatchCaseSensitiveDelimiter
	V2CallMethodsWithLegacySemantics
	V2FormatByteArrayAsArray
	V2FormatBytesWithLegacySemantics
	V2FormatDurationAsNano
	V2ReportErrorsWithLegacySemantics
	V2StringifyWithLegacySemantics
)

Jump to

Keyboard shortcuts

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