value

package
v0.0.0-...-ad801e6 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFieldIterator

func NewFieldIterator(v *Value) field.Iterator

NewFieldIterator creates a new field iterator from a JSON value. NB(xichen): This iterator currently skips all nested JSON arrays.

Types

type Array

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

Array is an array of values.

func NewArray

func NewArray(raw []*Value, p *BucketizedArrayPool) Array

NewArray creates a new value array.

func (*Array) Append

func (a *Array) Append(v *Value)

Append appends a value to the end of the value array.

func (Array) Capacity

func (a Array) Capacity() int

Capacity returns the capacity of the underlying array.

func (Array) Close

func (a Array) Close()

Close closes the value array.

func (Array) Len

func (a Array) Len() int

Len returns the number of values.

func (Array) Raw

func (a Array) Raw() []*Value

Raw returns the raw underlying value array.

func (*Array) Reset

func (a *Array) Reset()

Reset resets the value array.

type ArrayBucket

type ArrayBucket struct {
	// Capacity is the size of each element in the bucket.
	Capacity int

	// Count is the number of fixed elements in the bucket.
	Count int

	// Options is an optional override to specify options to use for a bucket,
	// specify nil to use the options specified to the bucketized pool
	// constructor for this bucket.
	Options *ArrayPoolOptions
}

ArrayBucket specifies a bucket.

type ArrayPool

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

ArrayPool is a value pool.

func NewArrayPool

func NewArrayPool(opts *ArrayPoolOptions) *ArrayPool

NewArrayPool creates a new pool.

func (*ArrayPool) Get

func (p *ArrayPool) Get() Array

Get gets a value from the pool.

func (*ArrayPool) Init

func (p *ArrayPool) Init(alloc func() Array)

Init initializes the pool.

func (*ArrayPool) Put

func (p *ArrayPool) Put(v Array)

Put returns a value to pool.

type ArrayPoolOptions

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

ArrayPoolOptions provide a set of options for the value pool.

func NewArrayPoolOptions

func NewArrayPoolOptions() *ArrayPoolOptions

NewArrayPoolOptions create a new set of value pool options.

func (*ArrayPoolOptions) InstrumentOptions

func (o *ArrayPoolOptions) InstrumentOptions() instrument.Options

InstrumentOptions returns the instrument options.

func (*ArrayPoolOptions) RefillHighWatermark

func (o *ArrayPoolOptions) RefillHighWatermark() float64

RefillHighWatermark returns the high watermark for stop refilling the pool.

func (*ArrayPoolOptions) RefillLowWatermark

func (o *ArrayPoolOptions) RefillLowWatermark() float64

RefillLowWatermark returns the low watermark for refilling the pool.

func (*ArrayPoolOptions) SetInstrumentOptions

func (o *ArrayPoolOptions) SetInstrumentOptions(v instrument.Options) *ArrayPoolOptions

SetInstrumentOptions sets the instrument options.

func (*ArrayPoolOptions) SetRefillHighWatermark

func (o *ArrayPoolOptions) SetRefillHighWatermark(v float64) *ArrayPoolOptions

SetRefillHighWatermark sets the high watermark for refilling the pool.

func (*ArrayPoolOptions) SetRefillLowWatermark

func (o *ArrayPoolOptions) SetRefillLowWatermark(v float64) *ArrayPoolOptions

SetRefillLowWatermark sets the low watermark for refilling the pool.

func (*ArrayPoolOptions) SetSize

func (o *ArrayPoolOptions) SetSize(v int) *ArrayPoolOptions

SetSize sets the pool size.

func (*ArrayPoolOptions) Size

func (o *ArrayPoolOptions) Size() int

Size returns pool size.

type BucketizedArrayPool

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

BucketizedArrayPool is a bucketized value pool.

func NewBucketizedArrayPool

func NewBucketizedArrayPool(sizes []ArrayBucket, opts *ArrayPoolOptions) *BucketizedArrayPool

NewBucketizedArrayPool creates a bucketized object pool.

func (*BucketizedArrayPool) Get

func (p *BucketizedArrayPool) Get(capacity int) Array

Get gets a value from the pool.

func (*BucketizedArrayPool) Init

func (p *BucketizedArrayPool) Init(alloc func(capacity int) Array)

Init initializes the bucketized pool.

func (*BucketizedArrayPool) Put

func (p *BucketizedArrayPool) Put(v Array, capacity int)

Put puts a value to the pool.

type BucketizedKVArrayPool

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

BucketizedKVArrayPool is a bucketized value pool.

func NewBucketizedKVArrayPool

func NewBucketizedKVArrayPool(sizes []KVArrayBucket, opts *KVArrayPoolOptions) *BucketizedKVArrayPool

NewBucketizedKVArrayPool creates a bucketized object pool.

func (*BucketizedKVArrayPool) Get

func (p *BucketizedKVArrayPool) Get(capacity int) KVArray

Get gets a value from the pool.

func (*BucketizedKVArrayPool) Init

func (p *BucketizedKVArrayPool) Init(alloc func(capacity int) KVArray)

Init initializes the bucketized pool.

func (*BucketizedKVArrayPool) Put

func (p *BucketizedKVArrayPool) Put(v KVArray, capacity int)

Put puts a value to the pool.

type KV

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

KV is a key value pair.

func NewKV

func NewKV(k string, v *Value) KV

NewKV creates a new key value pair.

func (KV) Key

func (kv KV) Key() string

Key returns the key.

func (KV) Value

func (kv KV) Value() *Value

Value returns the value.

type KVArray

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

KVArray is an array of key value pairs.

func NewKVArray

func NewKVArray(raw []KV, p *BucketizedKVArrayPool) KVArray

NewKVArray creates a new KV array.

func (*KVArray) Append

func (a *KVArray) Append(v KV)

Append appends a key value pair to the end of the KV array.

func (KVArray) Capacity

func (a KVArray) Capacity() int

Capacity returns the capacity of the underlying array.

func (KVArray) Close

func (a KVArray) Close()

Close closes the kv array.

func (KVArray) Len

func (a KVArray) Len() int

Len returns the number of key value pairs.

func (*KVArray) Reset

func (a *KVArray) Reset()

Reset reset the kv array.

type KVArrayBucket

type KVArrayBucket struct {
	// Capacity is the size of each element in the bucket.
	Capacity int

	// Count is the number of fixed elements in the bucket.
	Count int

	// Options is an optional override to specify options to use for a bucket,
	// specify nil to use the options specified to the bucketized pool
	// constructor for this bucket.
	Options *KVArrayPoolOptions
}

KVArrayBucket specifies a bucket.

type KVArrayPool

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

KVArrayPool is a value pool.

func NewKVArrayPool

func NewKVArrayPool(opts *KVArrayPoolOptions) *KVArrayPool

NewKVArrayPool creates a new pool.

func (*KVArrayPool) Get

func (p *KVArrayPool) Get() KVArray

Get gets a value from the pool.

func (*KVArrayPool) Init

func (p *KVArrayPool) Init(alloc func() KVArray)

Init initializes the pool.

func (*KVArrayPool) Put

func (p *KVArrayPool) Put(v KVArray)

Put returns a value to pool.

type KVArrayPoolOptions

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

KVArrayPoolOptions provide a set of options for the value pool.

func NewKVArrayPoolOptions

func NewKVArrayPoolOptions() *KVArrayPoolOptions

NewKVArrayPoolOptions create a new set of value pool options.

func (*KVArrayPoolOptions) InstrumentOptions

func (o *KVArrayPoolOptions) InstrumentOptions() instrument.Options

InstrumentOptions returns the instrument options.

func (*KVArrayPoolOptions) RefillHighWatermark

func (o *KVArrayPoolOptions) RefillHighWatermark() float64

RefillHighWatermark returns the high watermark for stop refilling the pool.

func (*KVArrayPoolOptions) RefillLowWatermark

func (o *KVArrayPoolOptions) RefillLowWatermark() float64

RefillLowWatermark returns the low watermark for refilling the pool.

func (*KVArrayPoolOptions) SetInstrumentOptions

func (o *KVArrayPoolOptions) SetInstrumentOptions(v instrument.Options) *KVArrayPoolOptions

SetInstrumentOptions sets the instrument options.

func (*KVArrayPoolOptions) SetRefillHighWatermark

func (o *KVArrayPoolOptions) SetRefillHighWatermark(v float64) *KVArrayPoolOptions

SetRefillHighWatermark sets the high watermark for refilling the pool.

func (*KVArrayPoolOptions) SetRefillLowWatermark

func (o *KVArrayPoolOptions) SetRefillLowWatermark(v float64) *KVArrayPoolOptions

SetRefillLowWatermark sets the low watermark for refilling the pool.

func (*KVArrayPoolOptions) SetSize

func (o *KVArrayPoolOptions) SetSize(v int) *KVArrayPoolOptions

SetSize sets the pool size.

func (*KVArrayPoolOptions) Size

func (o *KVArrayPoolOptions) Size() int

Size returns pool size.

type Object

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

Object is an object containing a list of key value pairs.

func NewObject

func NewObject(kvs KVArray) Object

NewObject creates a new object.

func (*Object) At

func (o *Object) At(i int) KV

At returns the key value pair at given index.

func (*Object) Close

func (o *Object) Close()

Close closes the object.

func (*Object) Get

func (o *Object) Get(key string) (*Value, bool)

Get returns the value for the given key in the o, and a bool indicating whether the value is found.

func (*Object) Len

func (o *Object) Len() int

Len returns the number of items in the object.

func (*Object) MarshalTo

func (o *Object) MarshalTo(dst []byte) ([]byte, error)

MarshalTo appends marshaled o to dst and returns the result.

func (Object) Visit

func (o Object) Visit(f func(key string, v *Value))

Visit calls f for each item in the object in the original order.

f cannot hold key and/or v after returning.

type Pool

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

Pool is a value pool.

func NewPool

func NewPool(opts *PoolOptions) *Pool

NewPool creates a new pool.

func (*Pool) Get

func (p *Pool) Get() *Value

Get gets a value from the pool.

func (*Pool) Init

func (p *Pool) Init(alloc func() *Value)

Init initializes the pool.

func (*Pool) Put

func (p *Pool) Put(v *Value)

Put returns a value to pool.

type PoolOptions

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

PoolOptions provide a set of options for the value pool.

func NewPoolOptions

func NewPoolOptions() *PoolOptions

NewPoolOptions create a new set of value pool options.

func (*PoolOptions) InstrumentOptions

func (o *PoolOptions) InstrumentOptions() instrument.Options

InstrumentOptions returns the instrument options.

func (*PoolOptions) RefillHighWatermark

func (o *PoolOptions) RefillHighWatermark() float64

RefillHighWatermark returns the high watermark for stop refilling the pool.

func (*PoolOptions) RefillLowWatermark

func (o *PoolOptions) RefillLowWatermark() float64

RefillLowWatermark returns the low watermark for refilling the pool.

func (*PoolOptions) SetInstrumentOptions

func (o *PoolOptions) SetInstrumentOptions(v instrument.Options) *PoolOptions

SetInstrumentOptions sets the instrument options.

func (*PoolOptions) SetRefillHighWatermark

func (o *PoolOptions) SetRefillHighWatermark(v float64) *PoolOptions

SetRefillHighWatermark sets the high watermark for refilling the pool.

func (*PoolOptions) SetRefillLowWatermark

func (o *PoolOptions) SetRefillLowWatermark(v float64) *PoolOptions

SetRefillLowWatermark sets the low watermark for refilling the pool.

func (*PoolOptions) SetSize

func (o *PoolOptions) SetSize(v int) *PoolOptions

SetSize sets the pool size.

func (*PoolOptions) Size

func (o *PoolOptions) Size() int

Size returns pool size.

type Type

type Type int

Type is a value type.

const (
	UnknownType Type = iota
	NullType
	BoolType
	BytesType
	NumberType
	ArrayType
	ObjectType
)

A list of supported value types.

func (Type) String

func (t Type) String() string

String returns string representation of t.

type Value

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

Value is a union of different types of values. There is at most one value in the union that is active at any point in time. The active value is determined by the type field in the value.

func NewArrayValue

func NewArrayValue(a Array, p *Pool) *Value

NewArrayValue creates a new array value.

func NewBoolValue

func NewBoolValue(b bool, p *Pool) *Value

NewBoolValue creates a new boolean value.

func NewBytesValue

func NewBytesValue(b []byte, p *Pool) *Value

NewBytesValue creates a new bytes value.

func NewEmptyValue

func NewEmptyValue(p *Pool) *Value

NewEmptyValue creates an empty value associated with the given pool.

func NewNullValue

func NewNullValue(p *Pool) *Value

NewNullValue creates a new null value.

func NewNumberValue

func NewNumberValue(n float64, p *Pool) *Value

NewNumberValue creates a new number value.

func NewObjectValue

func NewObjectValue(o Object, p *Pool) *Value

NewObjectValue creates a new object value.

func (*Value) Array

func (v *Value) Array() (Array, error)

Array returns an array value if the value type is array, or an error otherwise.

func (*Value) Bool

func (v *Value) Bool() (bool, error)

Bool returns a boolean value if the value type is boolean, or an error otherwise.

func (*Value) Bytes

func (v *Value) Bytes() ([]byte, error)

Bytes returns a bytes value if the value type is bytes, or an error otherwise.

func (*Value) Close

func (v *Value) Close()

Close closes the value and returns objects to pools where necessary.

func (*Value) Get

func (v *Value) Get(keys ...string) (*Value, bool)

Get returns value by the given keys path, and a boolean value indicating whether the key at path exists.

NB: array indexes may be represented as decimal numbers in keys.

func (*Value) MarshalTo

func (v *Value) MarshalTo(dst []byte) ([]byte, error)

MarshalTo appends marshaled v to dst and returns the result.

func (*Value) MustArray

func (v *Value) MustArray() Array

MustArray returns an array value or panics if the value type is not array.

func (*Value) MustBool

func (v *Value) MustBool() bool

MustBool returns a boolean value or panics if the value type is not boolean.

func (*Value) MustBytes

func (v *Value) MustBytes() []byte

MustBytes returns a bytes value or panics if the value type is not bytes.

func (*Value) MustNumber

func (v *Value) MustNumber() float64

MustNumber returns a numeric value or panics if the value type is not number.

func (*Value) MustObject

func (v *Value) MustObject() Object

MustObject returns an object value or panics if the value type is not object.

func (*Value) Number

func (v *Value) Number() (float64, error)

Number returns a numeric value if the value type is number, or an error otherwise.

func (*Value) Object

func (v *Value) Object() (Object, error)

Object returns an object value if the value type is object, or an error otherwise.

func (*Value) Reset

func (v *Value) Reset()

Reset resets the value.

func (*Value) SetArray

func (v *Value) SetArray(a Array)

SetArray sets the value to an array value.

func (*Value) SetBool

func (v *Value) SetBool(b bool)

SetBool sets the value to a boolean value.

func (*Value) SetBytes

func (v *Value) SetBytes(s []byte)

SetBytes sets the value to a bytes value.

func (*Value) SetNull

func (v *Value) SetNull()

SetNull sets the value to a null value.

func (*Value) SetNumber

func (v *Value) SetNumber(n float64)

SetNumber sets the value to a numeric value.

func (*Value) SetObject

func (v *Value) SetObject(o Object)

SetObject sets the value to an object value.

func (*Value) Type

func (v *Value) Type() Type

Type returns the value type.

Jump to

Keyboard shortcuts

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