Documentation
¶
Overview ¶
Package wirejson is the JSON reader behind the generated model decoders (models/models_gen.go) and the WebSocket frame router.
A decoder reads the text once, front to back, and validates every byte it passes, including values it skips. It accepts and rejects exactly what encoding/json accepted with the SDK's earlier decoders, and produces the same values:
- keys match field names exactly, then without case (encoding/json's folding);
- unknown keys are skipped but must still be valid JSON;
- a repeated key decodes again into the value already there (objects merge, lists reuse their elements), as encoding/json does;
- strings are unescaped like encoding/json: invalid UTF-8 and lone surrogates become U+FFFD;
- nesting deeper than 10000 is an error.
Index ¶
- Variables
- func At(err error, typeName, field string) error
- func DecodeAny(r *Reader) (any, error)
- func DecodeBool(r *Reader, dst *bool) error
- func DecodeBoolPtr(r *Reader, dst **bool) error
- func DecodeInt[T signed](r *Reader, dst *T) error
- func DecodeIntPtr[T signed](r *Reader, dst **T) error
- func DecodeQuotedInt[T ~int64](r *Reader, dst *T) error
- func DecodeQuotedUint[T ~uint64](r *Reader, dst *T) error
- func DecodeRaw(r *Reader, dst *json.RawMessage) error
- func DecodeString[S ~string](r *Reader, dst *S) error
- func DecodeStringIntPtr[T ~int64](r *Reader, dst **T) error
- func DecodeStringList[S ~string](r *Reader, dst *[]S) error
- func DecodeStringUintPtr[T ~uint64](r *Reader, dst **T) error
- func DecodeTime(r *Reader, dst *time.Time) error
- func DecodeTimePtr(r *Reader, dst **time.Time) error
- func DecodeUint[T unsigned](r *Reader, dst *T) error
- func DecodeUint64s[S ~[]uint64](r *Reader, dst *S) error
- func DecodeUintList[T unsigned](r *Reader, dst *[]T) error
- func DecodeUintPtr[T unsigned](r *Reader, dst **T) error
- func FinishLite(r *Reader, enc LiteEncoder, full []byte) ([]byte, error)
- func Fold(out, key []byte) []byte
- func FoldedIndex(key []byte, folded []string) int
- func Grow[E any](s []E, i int) []E
- func LiteList(r *Reader, out []byte, item LiteEncoder) ([]byte, error)
- func Lookup[T any]() func([]byte, *T) error
- func NoLiteName(typeName string, key []byte) error
- func Register[T any](unmarshal func([]byte, *T) error)
- func RegisterLite[T any](unmarshal func([]byte, *T) error, toLite func([]byte) ([]byte, error))
- func ToLite[T any](full []byte) ([]byte, error)
- func Trim[E any](s []E, n int) []E
- func Unexpected[T any](r *Reader) error
- func Unmarshal[T any](data []byte, v *T) error
- func UnmarshalLite[T any](data []byte, v *T) error
- func ValidNumber(s []byte) bool
- type LiteEncoder
- type Reader
- func (r *Reader) AppendRaw(out []byte) ([]byte, error)
- func (r *Reader) Bool() (bool, error)
- func (r *Reader) Elem(first bool) (ok bool, err error)
- func (r *Reader) End() error
- func (r *Reader) Fail(err error) error
- func (r *Reader) Lite() bool
- func (r *Reader) Member(first bool) (key []byte, ok bool, err error)
- func (r *Reader) Next() byte
- func (r *Reader) Null() (bool, error)
- func (r *Reader) Number() ([]byte, error)
- func (r *Reader) OpenArray() error
- func (r *Reader) OpenObject() error
- func (r *Reader) Raw() ([]byte, error)
- func (r *Reader) Skip() error
- func (r *Reader) String() ([]byte, error)
- func (r *Reader) Unexpected(t reflect.Type) error
Constants ¶
This section is empty.
Variables ¶
var ErrNoLite = errors.New("type has no lite encoding")
ErrNoLite is the error for a type with no lite form (edge types, or any type that is not a model).
var ErrNull = errors.New("required field cannot be null")
ErrNull is the error for null in a required field that is not nullable.
Functions ¶
func At ¶
At records that err happened in field (a JSON name) of the model typeName. A type error gets the field in its path; any other error, except a syntax error, is wrapped once, at the innermost field. Error paths stay out of line so the generated decoders stay small.
func DecodeAny ¶
DecodeAny decodes the next value as json.Unmarshal into an `any` does: map[string]any (a repeated key keeps its last value), []any, string, float64, bool or nil.
func DecodeBool ¶
DecodeBool: true or false; null keeps the old value.
func DecodeIntPtr ¶
DecodeIntPtr: null sets nil.
func DecodeQuotedInt ¶
DecodeQuotedInt is DecodeQuotedUint for int64.
func DecodeQuotedUint ¶
DecodeQuotedUint is a required uint64: a string holding a JSON integer (whitespace around it is allowed); "null" in the string keeps the old value.
func DecodeRaw ¶
func DecodeRaw(r *Reader, dst *json.RawMessage) error
DecodeRaw copies any value's text (null is kept as "null").
func DecodeString ¶
DecodeString: a string; null keeps the old value.
func DecodeStringIntPtr ¶
DecodeStringIntPtr is DecodeStringUintPtr for int64.
func DecodeStringList ¶
DecodeStringList is a list of strings (null items keep the item already there); null is nil.
func DecodeStringUintPtr ¶
DecodeStringUintPtr is an optional uint64 sent as a string.
func DecodeTime ¶
DecodeTime is a timestamp: a string of integer nanoseconds (strconv.ParseInt, so a leading '+' is allowed), as UTC. A bad text gives strconv.ParseInt's error, as before.
func DecodeTimePtr ¶
DecodeTimePtr: null sets nil.
func DecodeUint ¶
DecodeUint: a JSON number that is an integer in range (strconv.ParseUint of its text); null keeps the old value.
func DecodeUint64s ¶
DecodeUint64s is a list of 64-bit integers, each a string or a number holding only digits (the string is not unescaped). null is an empty list. The list is always replaced.
func DecodeUintList ¶
DecodeUintList is DecodeStringList for small unsigned integers.
func DecodeUintPtr ¶
DecodeUintPtr: null sets nil.
func FinishLite ¶
func FinishLite(r *Reader, enc LiteEncoder, full []byte) ([]byte, error)
FinishLite runs a generated lite encoder over the whole text r reads (full is that text).
func Fold ¶
Fold appends key folded as encoding/json folds field names (ASCII upper case, other runes to the smallest rune of their case-fold set), so two keys match without case when their folds are equal.
func FoldedIndex ¶
FoldedIndex returns the index of the name in folded (names already folded) that key matches without case, or -1. It is the slow path after an exact match failed.
func Grow ¶
Grow makes s[i] addressable for decoding list item i, as encoding/json does: an item already there is decoded into again.
func LiteList ¶
func LiteList(r *Reader, out []byte, item LiteEncoder) ([]byte, error)
LiteList is a lite encoder for a list of items that each have encoder item (null is copied).
func NoLiteName ¶
NoLiteName is the error for a key the type typeName has no lite name for.
func RegisterLite ¶
RegisterLite records the generated lite codec of a model type: its lite decoder and its full-to-lite renamer.
func ToLite ¶
ToLite rewrites full, the full-encoding text of a T (as encoding/json writes it), into the lite encoding: same values, each key renamed by its type. A key T has no lite name for is an error.
func Unmarshal ¶
Unmarshal decodes data into v with T's generated decoder, or with encoding/json when T has none.
func UnmarshalLite ¶
UnmarshalLite decodes lite-encoding data into v with T's generated decoder. There is no encoding/json fallback: a type without one is ErrNoLite.
Types ¶
type LiteEncoder ¶
LiteEncoder appends the lite form of the full-encoding value at r to out (generated liteFrom<T>).
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader reads one JSON text. The zero value is not usable; use NewReader.
func NewLiteReader ¶
NewLiteReader reads data in the lite encoding: the generated decoders match each type's lite keys (exactly, without case folding) instead of its full ones. Everything else is the same.
func (*Reader) Elem ¶
Elem moves to the next element of an open array. ok is false at the closing ']', which it consumes.
func (*Reader) Fail ¶
Fail is the error a whole-text decode returns for err: encoding/json checks the whole text before decoding, so invalid JSON anywhere wins over an error found earlier in the text.
func (*Reader) Member ¶
Member reads the next key of an open object and the ':' after it. ok is false at the closing '}', which it consumes. first is true for the first call after OpenObject.
func (*Reader) Next ¶
Next returns the first byte of the next value (after whitespace), or 0 at the end of the input.