jsonvector

package module
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2024 License: MIT Imports: 9 Imported by: 4

README

JSON vector

JSON parser based on Vector API with minimum memory consumption.

Usage
src := []byte(`{"id":1,"name":"Foo","price":123,"tags":["Bar","Eek"],"stock":{"warehouse":300,"retail":20}}`)
vec := jsonvector.Acquire()
defer jsonvector.Release(vec)
_ = vec.Parse(src)
fmt.Println(vec.Dot("stock.warehouse")) // 300

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Release

func Release(vec *Vector)

Release puts vector back to default pool instance.

func ReleaseNC added in v1.2.3

func ReleaseNC(vec *Vector)

ReleaseNC puts vector back to pool with enforced no-clear flag.

func Unescape

func Unescape(p []byte) []byte

Unescape byte array using itself as a destination.

Types

type Helper

type Helper struct{}

func (Helper) Beautify

func (h Helper) Beautify(w io.Writer, node *vector.Node) error

func (Helper) Indirect

func (h Helper) Indirect(p *vector.Byteptr) []byte

func (Helper) Marshal added in v1.2.2

func (h Helper) Marshal(w io.Writer, node *vector.Node) error

type Pool

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

Pool represents JSON vectors pool.

var (
	// P is a default instance of the pool.
	// Just call urlvector.Acquire() and urlvector.Release().
	P Pool
)

func (*Pool) Get

func (p *Pool) Get() *Vector

Get old vector from the pool or create new one.

func (*Pool) Put

func (p *Pool) Put(vec *Vector)

Put vector back to the pool.

type Vector

type Vector struct {
	vector.Vector
}

Vector represents URL parser.

func Acquire

func Acquire() *Vector

Acquire returns vector from default pool instance.

func NewVector

func NewVector() *Vector

NewVector makes new parser.

func (*Vector) Parse

func (vec *Vector) Parse(s []byte) error

Parse source bytes.

func (*Vector) ParseCopy

func (vec *Vector) ParseCopy(s []byte) error

ParseCopy copies source bytes and parse it.

func (*Vector) ParseCopyStr

func (vec *Vector) ParseCopyStr(s string) error

ParseCopyStr copies source string and parse it.

func (*Vector) ParseStr

func (vec *Vector) ParseStr(s string) error

ParseStr parses source string.

Jump to

Keyboard shortcuts

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