Documentation ¶
Index ¶
- Constants
- Variables
- type Byteptr
- func (p *Byteptr) Bytes() []byte
- func (p *Byteptr) CheckBit(pos int) bool
- func (p *Byteptr) Init(s []byte, offset, len int) *Byteptr
- func (p *Byteptr) InitRaw(addr uintptr, offset, len int) *Byteptr
- func (p *Byteptr) InitStr(s string, offset, len int) *Byteptr
- func (p *Byteptr) InitString(s string, offset, len int) *Byteptr
- func (p *Byteptr) Len() int
- func (p *Byteptr) Offset() int
- func (p *Byteptr) RawBytes() []byte
- func (p *Byteptr) RawString() string
- func (p *Byteptr) Reset()
- func (p *Byteptr) SetAddr(addr uintptr, cap int) *Byteptr
- func (p *Byteptr) SetBit(pos int, value bool)
- func (p *Byteptr) SetLen(len int) *Byteptr
- func (p *Byteptr) SetOffset(offset int) *Byteptr
- func (p *Byteptr) String() string
- func (p *Byteptr) TakeAddr(s []byte) *Byteptr
- func (p *Byteptr) TakeStrAddr(s string) *Byteptr
- func (p *Byteptr) TakeStringAddr(s string) *Byteptr
- type Helper
- type Index
- type Interface
- type Node
- func (n *Node) Array() *Node
- func (n *Node) At(idx int) *Node
- func (n *Node) Beautify(w io.Writer) error
- func (n *Node) Bool() bool
- func (n *Node) Bytes() []byte
- func (n *Node) Children() []Node
- func (n *Node) ChildrenIndices() []int
- func (n *Node) Depth() int
- func (n *Node) Dot(path string) *Node
- func (n *Node) DotArray(path string) *Node
- func (n *Node) DotBool(path string) bool
- func (n *Node) DotBytes(path string) []byte
- func (n *Node) DotFloat(path string) (float64, error)
- func (n *Node) DotInt(path string) (int64, error)
- func (n *Node) DotObject(path string) *Node
- func (n *Node) DotString(path string) string
- func (n *Node) DotUint(path string) (uint64, error)
- func (n *Node) Each(fn func(idx int, node *Node))
- func (n *Node) EqualWith(exp *Node) bool
- func (n *Node) Exists(key string) bool
- func (n *Node) Float() (float64, error)
- func (n *Node) ForceBytes() []byte
- func (n *Node) ForceString() string
- func (n *Node) Get(keys ...string) *Node
- func (n *Node) GetArray(keys ...string) *Node
- func (n *Node) GetArrayPS(path, separator string) *Node
- func (n *Node) GetBool(keys ...string) bool
- func (n *Node) GetBoolPS(path, separator string) bool
- func (n *Node) GetBytes(keys ...string) []byte
- func (n *Node) GetBytesPS(path, separator string) []byte
- func (n *Node) GetFloat(keys ...string) (float64, error)
- func (n *Node) GetFloatPS(path, separator string) (float64, error)
- func (n *Node) GetInt(keys ...string) (int64, error)
- func (n *Node) GetIntPS(path, separator string) (int64, error)
- func (n *Node) GetObject(keys ...string) *Node
- func (n *Node) GetObjectPS(path, separator string) *Node
- func (n *Node) GetPS(path, separator string) *Node
- func (n *Node) GetString(keys ...string) string
- func (n *Node) GetStringPS(path, separator string) string
- func (n *Node) GetUint(keys ...string) (uint64, error)
- func (n *Node) GetUintPS(path, separator string) (uint64, error)
- func (n *Node) Index() int
- func (n *Node) Int() (int64, error)
- func (n *Node) Key() *Byteptr
- func (n *Node) KeyBytes() []byte
- func (n *Node) KeyString() string
- func (n *Node) Limit() int
- func (n *Node) Look(key string) *Node
- func (n *Node) Marshal(w io.Writer) error
- func (n *Node) Object() *Node
- func (n *Node) Offset() int
- func (n *Node) RawBytes() []byte
- func (n *Node) RemoveIf(cond func(idx int, node *Node) bool)
- func (n *Node) Reset() *Node
- func (n *Node) SetLimit(limit int) *Node
- func (n *Node) SetOffset(offset int) *Node
- func (n *Node) SetType(typ Type)
- func (n *Node) Sort() *Node
- func (n *Node) SortKeys() *Node
- func (n *Node) String() string
- func (n *Node) SwapWith(node *Node)
- func (n *Node) Type() Type
- func (n *Node) Uint() (uint64, error)
- func (n *Node) Value() *Byteptr
- type Type
- type Vector
- func (vec *Vector) Beautify(w io.Writer) error
- func (vec *Vector) Buf() []byte
- func (vec *Vector) BufAppend(s []byte)
- func (vec *Vector) BufAppendByte(b byte)
- func (vec *Vector) BufAppendFloat(f float64)
- func (vec *Vector) BufAppendFloatTune(f float64, fmt byte, prec, bitSize int)
- func (vec *Vector) BufAppendInt(i int64)
- func (vec *Vector) BufAppendStr(s string)
- func (vec *Vector) BufAppendUint(u uint64)
- func (vec *Vector) BufLen() int
- func (vec *Vector) BufUpdateWith(b []byte)
- func (vec *Vector) Dot(path string) *Node
- func (vec *Vector) DotArray(path string) *Node
- func (vec *Vector) DotBool(path string) bool
- func (vec *Vector) DotBytes(path string) []byte
- func (vec *Vector) DotFloat(path string) (float64, error)
- func (vec *Vector) DotInt(path string) (int64, error)
- func (vec *Vector) DotObject(path string) *Node
- func (vec *Vector) DotString(path string) string
- func (vec *Vector) DotUint(path string) (uint64, error)
- func (vec *Vector) Each(fn func(idx int, node *Node))
- func (vec *Vector) EqualWith(exp *Vector) bool
- func (vec *Vector) ErrorOffset() int
- func (vec *Vector) Exists(key string) bool
- func (vec *Vector) ForgetFrom(idx int)
- func (vec *Vector) Get(keys ...string) *Node
- func (vec *Vector) GetArray(keys ...string) *Node
- func (vec *Vector) GetArrayPS(path, separator string) *Node
- func (vec *Vector) GetBool(keys ...string) bool
- func (vec *Vector) GetBoolPS(path, separator string) bool
- func (vec *Vector) GetByIdx(idx int) *Node
- func (vec *Vector) GetBytes(keys ...string) []byte
- func (vec *Vector) GetBytesPS(path, separator string) []byte
- func (vec *Vector) GetChild(root *Node, depth int) (*Node, int)
- func (vec *Vector) GetChildWT(root *Node, depth int, typ Type) (*Node, int)
- func (vec *Vector) GetFloat(keys ...string) (float64, error)
- func (vec *Vector) GetFloatPS(path, separator string) (float64, error)
- func (vec *Vector) GetInt(keys ...string) (int64, error)
- func (vec *Vector) GetIntPS(path, separator string) (int64, error)
- func (vec *Vector) GetNode(depth int) (node *Node, idx int)
- func (vec *Vector) GetNodeWT(depth int, typ Type) (*Node, int)
- func (vec *Vector) GetObject(keys ...string) *Node
- func (vec *Vector) GetObjectPS(path, separator string) *Node
- func (vec *Vector) GetPS(path, separator string) *Node
- func (vec *Vector) GetString(keys ...string) string
- func (vec *Vector) GetStringPS(path, separator string) string
- func (vec *Vector) GetUint(keys ...string) (uint64, error)
- func (vec *Vector) GetUintPS(path, separator string) (uint64, error)
- func (vec *Vector) KeepPtr()
- func (vec *Vector) Len() int
- func (vec *Vector) Marshal(w io.Writer) error
- func (vec *Vector) NodeAt(idx int) *Node
- func (vec *Vector) Parse(_ []byte) error
- func (vec *Vector) ParseCopy(_ []byte) error
- func (vec *Vector) ParseCopyStr(_ string) error
- func (vec *Vector) ParseStr(_ string) error
- func (vec *Vector) Prealloc(size uint)
- func (vec *Vector) PutNode(idx int, node *Node)
- func (vec *Vector) RemoveIf(cond func(idx int, node *Node) bool)
- func (vec *Vector) Reset()
- func (vec *Vector) Root() *Node
- func (vec *Vector) RootByIndex(index int) *Node
- func (vec *Vector) RootLen() int
- func (vec *Vector) RootTop() *Node
- func (vec *Vector) SetErrOffset(offset int)
- func (vec *Vector) SetHelper(helper Helper)
- func (vec *Vector) SetSrc(s []byte, copy bool) error
- func (vec *Vector) Src() []byte
- func (vec *Vector) SrcAddr() uintptr
- func (vec *Vector) SrcAt(i int) byte
- func (vec *Vector) SrcLen() int
Constants ¶
const FlagNoClear = 0
FlagNoClear disables clear step.
Variables ¶
var ( ErrEmptySrc = errors.New("can't parse empty source") ErrShortSrc = errors.New("source is too short to parse") ErrNotImplement = errors.New("method not implemented") ErrIncompatType = errors.New("incompatible type") ErrNotFound = errors.New("node not found") ErrInternal = errors.New("internal vector error") ErrNoHelper = errors.New("helper not found") ErrUnparsedTail = errors.New("unparsed tail") ErrUnexpId = errors.New("unexpected identifier") ErrUnexpEOF = errors.New("unexpected end of file") ErrUnexpEOS = errors.New("unexpected end of string") )
Functions ¶
This section is empty.
Types ¶
type Byteptr ¶
type Byteptr struct {
// contains filtered or unexported fields
}
func (*Byteptr) InitString ¶ added in v1.2.5
func (*Byteptr) TakeStrAddr ¶ added in v1.2.5
DEPRECATED: use TakeStringAddr instead.
func (*Byteptr) TakeStringAddr ¶ added in v1.2.5
type Helper ¶
type Helper interface { // Indirect convert byteptr to byte slice and apply custom logic. Indirect(*Byteptr) []byte // Beautify makes a beauty view of node. Beautify(io.Writer, *Node) error // Marshal serializes node. Marshal(io.Writer, *Node) error }
Helper object interface.
type Index ¶
type Index struct {
// contains filtered or unexported fields
}
Index represents nodes index matrix.
Contain indexes of nodes in the vector divided by depth. Y-axis means depth, X-axis means position in index.
type Interface ¶
type Interface interface { SetHelper(helper Helper) Parse([]byte) error ParseCopy([]byte) error ParseStr(string) error ParseCopyStr(string) error Root() *Node RootByIndex(int) *Node RootTop() *Node Each(fn func(int, *Node)) Exists(string) bool Get(...string) *Node GetObject(...string) *Node GetArray(...string) *Node GetBytes(...string) []byte GetString(...string) string GetBool(...string) bool GetFloat(...string) (float64, error) GetInt(...string) (int64, error) GetUint(...string) (uint64, error) GetPS(string, string) *Node GetObjectPS(string, string) *Node GetArrayPS(string, string) *Node GetBytesPS(string, string) []byte GetStringPS(string, string) string GetBoolPS(string, string) bool GetFloatPS(string, string) (float64, error) GetIntPS(string, string) (int64, error) GetUintPS(string, string) (uint64, error) Dot(string) *Node DotObject(string) *Node DotArray(string) *Node DotBytes(string) []byte DotString(string) string DotBool(string) bool DotFloat(string) (float64, error) DotInt(string) (int64, error) DotUint(string) (uint64, error) KeepPtr() Beautify(io.Writer) error Marshal(io.Writer) error ErrorOffset() int Prealloc(uint) Reset() }
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node object.
func (*Node) Bytes ¶
Bytes returns value as bytes.
Allow only for [string, number, bool, attribute] types.
func (*Node) ChildrenIndices ¶ added in v1.2.3
ChildrenIndices returns list of indices of children nodes.
func (*Node) ForceBytes ¶
ForceBytes returns value as bytes independent of the type.
func (*Node) ForceString ¶
ForceString returns value as string independent of the type.
func (*Node) GetArrayPS ¶
GetArrayPS looks and get child array by given path and separator.
func (*Node) GetBytesPS ¶
GetBytesPS looks and get child bytes by given path and separator.
func (*Node) GetFloatPS ¶
GetFloatPS looks and get child float by given path and separator.
func (*Node) GetObjectPS ¶
GetObjectPS looks and get child object by given path and separator.
func (*Node) GetStringPS ¶
GetStringPS looks and get child string by given path and separator.
func (*Node) RemoveIf ¶ added in v1.2.3
RemoveIf deletes all children nodes satisfies condition cond.
type Vector ¶
type Vector struct { bitset.Bitset // Nodes index. Index Index // External helper object. Helper Helper // contains filtered or unexported fields }
Vector parser object.
func (*Vector) Beautify ¶
Beautify formats first root node in human-readable representation.
Second and next roots must beautify manually by call Beautify method of each node.
func (*Vector) BufAppendByte ¶
BufAppendByte appends single byte to the buffer.
func (*Vector) BufAppendFloat ¶
BufAppendFloat appends float to the buffer.
func (*Vector) BufAppendFloatTune ¶
BufAppendFloatTune appends float with extended params to the buffer.
func (*Vector) BufAppendInt ¶
BufAppendInt appends int to the buffer.
func (*Vector) BufAppendStr ¶
BufAppendStr appends string to the buffer.
func (*Vector) BufAppendUint ¶
BufAppendUint appends uint to the buffer.
func (*Vector) BufUpdateWith ¶
BufUpdateWith replaces buffer with b.
func (*Vector) ErrorOffset ¶
ErrorOffset returns last error offset.
func (*Vector) ForgetFrom ¶
ForgetFrom forgets nodes from given position to the end of the array.
func (*Vector) GetArrayPS ¶
GetArrayPS looks and get array by given path and separator.
func (*Vector) GetBytesPS ¶
GetBytesPS looks and get bytes by given path and separator.
func (*Vector) GetChild ¶
GetChild get node and register it as a child of root node.
Similar to GetNode.
func (*Vector) GetChildWT ¶
GetChildWT get node, register it as a child of root node and set type at once.
func (*Vector) GetFloatPS ¶
GetFloatPS looks and get float by given path and separator.
func (*Vector) GetObjectPS ¶
GetObjectPS looks and get object by given path and separator.
func (*Vector) GetStringPS ¶
GetStringPS looks and get string by given path and separator.
func (*Vector) KeepPtr ¶
func (vec *Vector) KeepPtr()
KeepPtr guarantees that vector object wouldn't be collected by GC.
Typically, vector objects uses together with pools and GC doesn't collect them. But for cases like vec := &Vector{...} node := vec.Get("foo", "bar") <- here GC may collect vec fmt.Println(node.String()) <- invalid operation due to vec already has been collected vec.KeepPtr() <- just call me to avoid that trouble
func (*Vector) Marshal ¶ added in v1.2.4
Marshal serializes first root node.
Second and next roots must beautify manually by call Marshal method of each node.
func (*Vector) ParseCopyStr ¶
ParseCopyStr copies source string and parse it.
func (*Vector) RootByIndex ¶
RootByIndex returns root node by given index.
For cases when one vector instance uses for parse many sources.
func (*Vector) SetErrOffset ¶
SetErrOffset sets error offset.
func (*Vector) Src ¶
Src returns raw source bytes.
Please note, source bytes may be "corrupt" when unescaped.