optdec

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
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
)
View Source
const (
	PosMask  = math.MaxUint64 << 32
	PosBits  = 32
	TypeMask = 0xFF
	TypeBits = 8

	ConLenMask = uint64(math.MaxUint32)
	ConLenBits = 32
)
View Source
const (
	OptionUseInt64         = consts.OptionUseInt64
	OptionUseNumber        = consts.OptionUseNumber
	OptionUseUnicodeErrors = consts.OptionUseUnicodeErrors
	OptionDisableUnknown   = consts.OptionDisableUnknown
	OptionCopyString       = consts.OptionCopyString
	OptionValidateString   = consts.OptionValidateString
)
View Source
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

View Source
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

func AsEfaceFast

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

func Decode

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

func Parse

func Parse(data string, opt uint64) error

func ParseBool

func ParseBool(raw string) (bool, error)

func ParseF64

func ParseF64(raw string) (float64, error)

func ParseI64

func ParseI64(raw string) (int64, error)

func ParseU64

func ParseU64(raw string) (uint64, error)

func 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.

func PtrOffset

func PtrOffset(ptr uintptr, off int64) uintptr

func SkipNumberFast

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

func SkipOneFast

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

func SkipOneFast2

func SkipOneFast2(json string, pos *int) (int, error)

func Unquote

func Unquote(raw string) (string, error)

func ValidNumberFast

func ValidNumberFast(json string) error

Types

type Array

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

func (*Array) Children

func (val *Array) Children() uintptr

func (Array) Len

func (arr Array) Len() int

type Context

type Context struct {
	Parser *Parser

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

func NewContext

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

func (*Context) Delete

func (ctx *Context) Delete()

func (*Context) Options

func (ctx *Context) Options() uint64

func (*Context) Root

func (ctx *Context) Root() Node

type Dom

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

type ErrorCode

type ErrorCode int

func (ErrorCode) Error

func (code ErrorCode) Error() string

type MismatchTypeError

type MismatchTypeError = errors.MismatchTypeError

type Node

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

func NewNode

func NewNode(cptr uintptr) Node

func (Node) Arr

func (val Node) Arr() Array

func (Node) Array

func (val Node) Array() Array

func (*Node) AsArr

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

func (Node) AsBool

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

func (Node) AsBytesRef

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

func (*Node) AsEface

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

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

func (*Node) AsEfaceFallback

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

func (Node) AsF64

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

func (Node) AsI64

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

func (*Node) AsMapEface

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

func (*Node) AsMapString

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

func (Node) AsNumber

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

func (*Node) AsObj

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

func (Node) AsRaw

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

func (*Node) AsSliceBytes

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

func (*Node) AsSliceEface

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

func (*Node) AsSliceI32

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

func (*Node) AsSliceI64

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

func (*Node) AsSliceString

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

func (*Node) AsSliceU32

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

func (*Node) AsSliceU64

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

func (Node) AsStr

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

func (Node) AsStrRef

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

func (Node) AsStringText

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

func (Node) AsU64

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

func (Node) Bool

func (val Node) Bool() bool

func (*Node) Equal

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

func (Node) F64

func (val Node) F64() float64

func (Node) I64

func (val Node) I64() int64

func (Node) IsNull

func (val Node) IsNull() bool

func (Node) IsNumber

func (val Node) IsNumber() bool

func (Node) IsRawNumber

func (val Node) IsRawNumber() bool

func (Node) IsStr

func (val Node) IsStr() bool

func (Node) Next

func (val Node) Next() uintptr

func (Node) NonstrAsNumber

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

func (Node) Number

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

func (Node) Obj

func (val Node) Obj() Object

func (Node) Object

func (val Node) Object() Object

func (Node) ParseBool

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

func (Node) ParseF64

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

func (Node) ParseI64

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

func (Node) ParseNumber

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

func (Node) ParseString

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

func (Node) ParseU64

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

func (Node) Position

func (val Node) Position() int

func (Node) Raw

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

func (Node) StringCopyEsc

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

func (Node) StringRef

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

reference from the input JSON as possible

func (Node) Type

func (val Node) Type() uint8

/ Helper functions to eliminate CGO calls

func (Node) U64

func (val Node) U64() uint64

type NodeIter

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

func NewNodeIter

func NewNodeIter(node Node) NodeIter

func (*NodeIter) Next

func (iter *NodeIter) Next() Node

func (*NodeIter) Peek

func (iter *NodeIter) Peek() Node

type Object

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

func (*Object) Children

func (val *Object) Children() uintptr

func (Object) Len

func (obj Object) Len() int

type Options

type Options = consts.Options

type Parser

type Parser struct {
	Json string

	Utf8Inv bool
	// contains filtered or unexported fields
}

should consitent with native/parser.c

func (*Parser) JsonBytes

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

func (*Parser) Pos

func (p *Parser) Pos() int

type SyntaxError

type SyntaxError = errors.SyntaxError

Jump to

Keyboard shortcuts

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