Search and commands

↑ ↓ to select · Enter to open · Esc to close

Type to search packages.

optdec

v1.15.5
github.com/bytedance/sonic/internal/decoder/optdec

Documentation

pkg.go.dev ↗

Table of contents

↓ to select · Enter to jump· Shift+Enter for source

137 matches

Top ↑

Constants

KNull (15 declarations)

const (
	// BasicType: 3 bits
	KNull   = 0 // xxxxx000
	KBool   = 2 // xxxxx010
	KNumber = 3 // xxxxx011
	KString = 4 // xxxxx100
	KRaw    = 5 // xxxxx101
	KObject = 6 // xxxxx110
	KArray  = 7 // xxxxx111

	// SubType: 2 bits
	KFalse         = (0 << 3) | KBool   // xxx00_010, 2
	KTrue          = (1 << 3) | KBool   // xxx01_010, 10
	KUint          = (0 << 3) | KNumber // xxx00_011, 3
	KSint          = (1 << 3) | KNumber // xxx01_011, 11
	KReal          = (2 << 3) | KNumber // xxx10_011, 19
	KRawNumber     = (3 << 3) | KNumber // xxx11_011, 27
	KStringCommon  = KString            // xxx00_100, 4
	KStringEscaped = (1 << 3) | KString // xxx01_100, 12
)

PosMask (6 declarations)

const (
	PosMask  = math.MaxUint64 << 32
	PosBits  = 32
	TypeMask = 0xFF
	TypeBits = 8

	ConLenMask = uint64(math.MaxUint32)
	ConLenBits = 32
)

OptionUseInt64 (6 declarations)

const (
	OptionUseInt64         = consts.OptionUseInt64
	OptionUseNumber        = consts.OptionUseNumber
	OptionUseUnicodeErrors = consts.OptionUseUnicodeErrors
	OptionDisableUnknown   = consts.OptionDisableUnknown
	OptionCopyString       = consts.OptionCopyString
	OptionValidateString   = consts.OptionValidateString
)

SONIC_OK (15 declarations)

const (
	SONIC_OK                      = 0
	SONIC_CONTROL_CHAR            = 1
	SONIC_INVALID_ESCAPED         = 2
	SONIC_INVALID_NUM             = 3
	SONIC_FLOAT_INF               = 4
	SONIC_EOF                     = 5
	SONIC_INVALID_CHAR            = 6
	SONIC_EXPECT_KEY              = 7
	SONIC_EXPECT_COLON            = 8
	SONIC_EXPECT_OBJ_COMMA_OR_END = 9
	SONIC_EXPECT_ARR_COMMA_OR_END = 10
	SONIC_VISIT_FAILED            = 11
	SONIC_INVALID_ESCAPED_UTF     = 12
	SONIC_INVALID_LITERAL         = 13
	SONIC_STACK_OVERFLOW          = 14
)

Variables

ParsingErrors

var ParsingErrors = []string{
	SONIC_OK:                      "ok",
	SONIC_CONTROL_CHAR:            "control chars in string",
	SONIC_INVALID_ESCAPED:         "invalid escaped chars in string",
	SONIC_INVALID_NUM:             "invalid number",
	SONIC_FLOAT_INF:               "float infinity",
	SONIC_EOF:                     "eof",
	SONIC_INVALID_CHAR:            "invalid chars",
	SONIC_EXPECT_KEY:              "expect a json key",
	SONIC_EXPECT_COLON:            "expect a `:`",
	SONIC_EXPECT_OBJ_COMMA_OR_END: "expect a `,` or `}`",
	SONIC_EXPECT_ARR_COMMA_OR_END: "expect a `,` or `]`",
	SONIC_VISIT_FAILED:            "failed in json visitor",
	SONIC_INVALID_ESCAPED_UTF:     "invalid escaped unicodes",
	SONIC_INVALID_LITERAL:         "invalid literal(true/false/null)",
	SONIC_STACK_OVERFLOW:          "json is exceeded max depth 4096, cause stack overflow",
}

Functions

AsEfaceFast

func AsEfaceFast(iter *NodeIter, ctx *Context) interface{}

Decode

func Decode(s *string, i *int, f uint64, val interface{}) error

Parse

func Parse(data string, opt uint64) error

ParseBool

func ParseBool(raw string) (bool, error)

ParseF64

func ParseF64(raw string) (float64, error)

ParseI64

func ParseI64(raw string) (int64, error)

ParseU64

func ParseU64(raw string) (uint64, error)

Pretouch

func Pretouch(vt reflect.Type, opts ...option.CompileOption) error

Pretouch compiles vt ahead-of-time to avoid JIT compilation on-the-fly, in order to reduce the first-hit latency.

Opts are the compile options, for example, "option.WithCompileRecursiveDepth" is a compile option to set the depth of recursive compile for the nested struct type.

PretouchMany

func PretouchMany(vts []reflect.Type, opts ...option.CompileOption) error

PretouchMany compiles all vts ahead-of-time to avoid JIT compilation on-the-fly, in order to reduce the first-hit latency.

PtrOffset

func PtrOffset(ptr uintptr, off int64) uintptr

SkipNumberFast

func SkipNumberFast(json string, start int) (int, bool)

SkipOneFast

func SkipOneFast(json string, pos int) (string, error)

Unquote

func Unquote(raw string) (string, error)

ValidNumberFast

func ValidNumberFast(raw string) bool

pos is the start index of the raw

Types

Array

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

Array.Children

func (val *Array) Children() uintptr

Array.Len

func (arr Array) Len() int

Context

type Context struct {
	Parser *Parser

	Stack   boundedStack
	Utf8Inv bool
	// contains filtered or unexported fields
}

NewContext

func NewContext(json string, pos int, opts uint64, root *rt.GoType) (Context, error)

Context.Delete

func (ctx *Context) Delete()

Context.Options

func (ctx *Context) Options() uint64

Context.Root

func (ctx *Context) Root() Node

Dom

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

ErrorCode

type ErrorCode int

ErrorCode.Error

func (code ErrorCode) Error() string

MismatchTypeError

type MismatchTypeError = errors.MismatchTypeError

Node

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

NewNode

func NewNode(cptr uintptr) Node

Node.Arr

func (val Node) Arr() Array

Node.Array

func (val Node) Array() Array

Node.AsArr

func (val *Node) AsArr() (Array, bool)

Node.AsBool

func (val Node) AsBool() (bool, bool)

Node.AsByte

func (self Node) AsByte(ctx *Context) (uint8, bool)

Node.AsEface

func (node *Node) AsEface(ctx *Context) (interface{}, error)

AsEface will always ok, because we have parse in native.

Node.AsEfaceFallback

func (node *Node) AsEfaceFallback(ctx *Context) (interface{}, error)

Node.AsF64

func (val Node) AsF64(ctx *Context) (float64, bool)

Node.AsI64

func (self Node) AsI64(ctx *Context) (int64, bool)

Node.AsMapEface

func (node *Node) AsMapEface(ctx *Context, vp unsafe.Pointer) error

Node.AsMapString

func (node *Node) AsMapString(ctx *Context, vp unsafe.Pointer) error

Node.AsNumber

func (val Node) AsNumber(ctx *Context) (json.Number, bool)

Node.AsObj

func (val *Node) AsObj() (Object, bool)

Node.AsRaw

func (val Node) AsRaw(ctx *Context) string

Node.AsSliceBytes

func (val *Node) AsSliceBytes(ctx *Context) ([]byte, error)

Node.AsSliceEface

func (node *Node) AsSliceEface(ctx *Context, vp unsafe.Pointer) error

Node.AsSliceI32

func (node *Node) AsSliceI32(ctx *Context, vp unsafe.Pointer) error

Node.AsSliceI64

func (node *Node) AsSliceI64(ctx *Context, vp unsafe.Pointer) error

Node.AsSliceString

func (node *Node) AsSliceString(ctx *Context, vp unsafe.Pointer) error

Node.AsSliceU32

func (node *Node) AsSliceU32(ctx *Context, vp unsafe.Pointer) error

Node.AsSliceU64

func (node *Node) AsSliceU64(ctx *Context, vp unsafe.Pointer) error

Node.AsStr

func (val Node) AsStr(ctx *Context) (string, bool)

Node.AsStrRef

func (val Node) AsStrRef(ctx *Context) (string, bool)

Node.AsStringText

func (val Node) AsStringText(ctx *Context) ([]byte, bool)

Node.AsU64

func (self Node) AsU64(ctx *Context) (uint64, bool)

Node.Bool

func (val Node) Bool() bool

Node.Equal

func (val *Node) Equal(ctx *Context, lhs string) bool

Node.F64

func (val Node) F64() float64

Node.I64

func (val Node) I64() int64

Node.IsNull

func (val Node) IsNull() bool

Node.IsNumber

func (val Node) IsNumber() bool

Node.IsRawNumber

func (val Node) IsRawNumber() bool

Node.IsStr

func (val Node) IsStr() bool

Node.Next

func (val Node) Next() uintptr

Node.NonstrAsNumber

func (val Node) NonstrAsNumber(ctx *Context) (json.Number, bool)

Node.Number

func (val Node) Number(ctx *Context) json.Number

Node.Obj

func (val Node) Obj() Object

Node.Object

func (val Node) Object() Object

Node.ParseBool

func (val Node) ParseBool(ctx *Context) (bool, bool)

Node.ParseF64

func (val Node) ParseF64(ctx *Context) (float64, bool)

Node.ParseI64

func (val Node) ParseI64(ctx *Context) (int64, bool)

Node.ParseNumber

func (val Node) ParseNumber(ctx *Context) (json.Number, bool)

Node.ParseString

func (val Node) ParseString(ctx *Context) (string, bool)

Node.ParseU64

func (val Node) ParseU64(ctx *Context) (uint64, bool)

Node.Position

func (val Node) Position() int

Node.Raw

func (val Node) Raw(ctx *Context) string

Node.StringCopyEsc

func (val Node) StringCopyEsc(ctx *Context) string

Node.StringRef

func (val Node) StringRef(ctx *Context) string

reference from the input JSON as possible

Node.Type

func (val Node) Type() uint8

/ Helper functions to eliminate CGO calls

Node.U64

func (val Node) U64() uint64

NodeIter

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

NewNodeIter

func NewNodeIter(node Node) NodeIter

NodeIter.Next

func (iter *NodeIter) Next() Node

NodeIter.Peek

func (iter *NodeIter) Peek() Node

Object

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

Object.Children

func (val *Object) Children() uintptr

Object.Len

func (obj Object) Len() int

Options

type Options = consts.Options

Parser

type Parser struct {
	Json string

	Utf8Inv bool
	// contains filtered or unexported fields
}

should consistent with native/parser.c

Parser.JsonBytes

func (p *Parser) JsonBytes() []byte

Parser.Pos

func (p *Parser) Pos() int

SyntaxError

type SyntaxError = errors.SyntaxError

Dependency graph