Documentation ¶
Index ¶
- Constants
- func AppendAnyValue(b []byte, v any) []byte
- func AppendFloat64(b []byte, f float64) []byte
- func AppendNumber[T constraints.Integer | constraints.Float](b []byte, n T) []byte
- func BytesToFloat64(b []byte) float64
- type Arena
- func (a *Arena) ApproxSize() int
- func (a *Arena) NewArray() *Value
- func (a *Arena) NewBinary(b []byte) *Value
- func (a *Arena) NewFalse() *Value
- func (a *Arena) NewFromFastJson(jv *fastjson.Value) *Value
- func (a *Arena) NewNull() *Value
- func (a *Arena) NewNumberFloat64(f float64) *Value
- func (a *Arena) NewNumberInt(n int) *Value
- func (a *Arena) NewObject() *Value
- func (a *Arena) NewString(s string) *Value
- func (a *Arena) NewStringBytes(s []byte) *Value
- func (a *Arena) NewTrue() *Value
- func (a *Arena) Reset()
- type ArenaPool
- type Object
- type Parser
- type ParserPool
- type Tuple
- type Type
- type Value
- func (v *Value) AppendBytes(b []byte) ([]byte, error)
- func (v *Value) Array() ([]*Value, error)
- func (v *Value) Bool() (bool, error)
- func (v *Value) Bytes() ([]byte, error)
- func (v *Value) Del(key string)
- func (v *Value) FastJson(a *fastjson.Arena) *fastjson.Value
- func (v *Value) Float64() (float64, error)
- func (v *Value) Get(keys ...string) *Value
- func (v *Value) GetArray(keys ...string) []*Value
- func (v *Value) GetBool(keys ...string) bool
- func (v *Value) GetBytes(keys ...string) []byte
- func (v *Value) GetFloat64(keys ...string) float64
- func (v *Value) GetInt(keys ...string) int
- func (v *Value) GetObject(keys ...string) *Object
- func (v *Value) GetString(keys ...string) string
- func (v *Value) GetStringBytes(keys ...string) []byte
- func (v *Value) GoType() any
- func (v *Value) Int() (int, error)
- func (v *Value) MarshalTo(dst []byte) []byte
- func (v *Value) Object() (*Object, error)
- func (v *Value) Set(key string, value *Value)
- func (v *Value) SetArrayItem(idx int, value *Value)
- func (v *Value) String() string
- func (v *Value) StringBytes() ([]byte, error)
- func (v *Value) Type() Type
Constants ¶
const ( TypeNull = Type(1) TypeNumber = Type(2) TypeString = Type(3) TypeFalse = Type(4) TypeTrue = Type(5) TypeArray = Type(6) TypeObject = Type(7) TypeBinary = Type(8) )
const EOS = byte(0)
Variables ¶
This section is empty.
Functions ¶
func AppendAnyValue ¶
AppendAnyValue appends encoded value to b. Supports only simple go types.
func AppendFloat64 ¶
AppendFloat64 encodes float64 as bytes that will be correctly comparable with byte.Compare
func AppendNumber ¶
func AppendNumber[T constraints.Integer | constraints.Float](b []byte, n T) []byte
AppendNumber encodes number
func BytesToFloat64 ¶
BytesToFloat64 decodes float64 from bytes encoded with AppendFloat64
Types ¶
type Arena ¶
type Arena struct {
// contains filtered or unexported fields
}
Arena may be used for fast creation and re-use of Values.
Typical Arena lifecycle:
- Construct Values via the Arena and Value.Set* calls.
- Marshal the constructed Values with Value.MarshalTo call.
- Reset all the constructed Values at once by Arena.Reset call.
- Go to 1 and re-use the Arena.
It is unsafe calling Arena methods from concurrent goroutines. Use per-goroutine Arenas or ArenaPool instead.
func (*Arena) ApproxSize ¶
ApproxSize returns approximate size of arena cache
func (*Arena) NewArray ¶
NewArray returns new empty array value.
New entries may be added to the returned array via Set* calls.
The returned array is valid until Reset is called on a.
func (*Arena) NewBinary ¶
NewBinary returns new binary value containing b.
The returned value is valid until Reset is called on a.
func (*Arena) NewFromFastJson ¶
NewFromFastJson creates Value from passed fastjson.Value
func (*Arena) NewNumberFloat64 ¶
NewNumberFloat64 returns new number value containing f.
The returned number is valid until Reset is called on a.
func (*Arena) NewNumberInt ¶
NewNumberInt returns new number value containing n.
The returned number is valid until Reset is called on a.
func (*Arena) NewObject ¶
NewObject returns new empty object value.
New entries may be added to the returned object via Set call.
The returned object is valid until Reset is called on a.
func (*Arena) NewString ¶
NewString returns new string value containing s.
The returned string is valid until Reset is called on a.
func (*Arena) NewStringBytes ¶
NewStringBytes returns new string value containing s.
The returned string is valid until Reset is called on a.
type ArenaPool ¶
type ArenaPool struct {
// contains filtered or unexported fields
}
ArenaPool may be used for pooling Arenas for similarly typed values.
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object represents an anyenc object
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses encoded bytes.
Parser may be re-used for subsequent parsing.
Parser cannot be used from concurrent goroutines. Use per-goroutine parsers or ParserPool instead.
func (*Parser) ApproxSize ¶
ApproxSize returns approximate size of parser cache
type ParserPool ¶
type ParserPool struct {
// contains filtered or unexported fields
}
ParserPool may be used for pooling Parsers for similarly typed values.
func (*ParserPool) Get ¶
func (pp *ParserPool) Get() *Parser
Get returns a Parser from pp.
The Parser must be Put to pp after use.
func (*ParserPool) Put ¶
func (pp *ParserPool) Put(p *Parser)
Put returns p to pp.
p and objects recursively returned from p cannot be used after p is put into pp.
type Tuple ¶
type Tuple []byte
Tuple represents an encoded sequence of values as a byte slice.
func (Tuple) AppendInverted ¶
AppendInverted adds a new encoded value and inverts bytes
func (Tuple) ReadBytes ¶
ReadBytes iterates over every value in the tuple and passes the raw bytes to the provided function `f`. It continues until all values are processed.
func (Tuple) ReadValues ¶
ReadValues decodes and reads all values from the start of the tuple. The provided function `f` is called for each value.
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value represents one decoded value.
func MustParseJson ¶
MustParseJson parses Value from json string. Panics in case of error
func (*Value) AppendBytes ¶
AppendBytes appends binary data to the given byte slice from a binary type value.
func (*Value) Array ¶
Array returns the value as an array of values or an error if it's not an array.
func (*Value) Bytes ¶
Bytes returns the binary data for a binary type or an error if it's not binary. Warning: the returned value is not a copy.
func (*Value) Get ¶
Get returns a value by the given key path.
Array indexes may be represented as decimal numbers in keys.
Returns nil for non-existing key paths.
The returned value is valid until Parse is called on the parser that returned v.
func (*Value) GetArray ¶
GetArray returns an array from the given path or nil if the value is not an array.
func (*Value) GetBool ¶
GetBool returns true if the value at the path is a boolean true, or false otherwise.
func (*Value) GetBytes ¶
GetBytes returns a byte slice from the given path or nil if the value is not binary.
func (*Value) GetFloat64 ¶
GetFloat64 returns a float64 from the given path or 0 if the value is not a number.
func (*Value) GetObject ¶
GetObject returns an object from the given path or nil if the value is not an object.
func (*Value) GetString ¶
GetString returns a string from the given path or an empty string if the value is not a string.
func (*Value) GetStringBytes ¶
GetStringBytes returns a byte slice from the given path or nil if the value is not a string.
func (*Value) GoType ¶
GoType converts the value to a Go primitive type.
Numbers are always float64. Arrays are []any. Objects are map[string]any.
func (*Value) MarshalTo ¶
MarshalTo appends the value to the given byte slice. You can pass nil as dst.
func (*Value) SetArrayItem ¶
SetArrayItem sets the value in the array v at the specified index.
func (*Value) String ¶
String returns a string (JSON) representation of the value. Use it for debugging purposes only.
func (*Value) StringBytes ¶
StringBytes returns the value as a byte slice or an error if it's not a string. Warning: the returned value is not a copy.