velocypack

package module
v0.0.0-...-5af53c2 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: Apache-2.0 Imports: 21 Imported by: 33

README

ArangoDB VelocyPack Go implementation.

Build Status GoDoc

NOTE: THIS IS WORK IN PROGRESS.

Documentation

Overview

Velocypack implementation for Go.

Index

Constants

This section is empty.

Variables

View Source
var (
	// NumberOutOfRangeError indicates an out of range error.
	NumberOutOfRangeError = errors.New("number out of range")
	// IsNumberOutOfRange returns true if the given error is an NumberOutOfRangeError.
	IsNumberOutOfRange = isCausedByFunc(NumberOutOfRangeError)
	// IndexOutOfBoundsError indicates an index outside of array/object bounds.
	IndexOutOfBoundsError = errors.New("index out of range")
	// IsIndexOutOfBounds returns true if the given error is an IndexOutOfBoundsError.
	IsIndexOutOfBounds = isCausedByFunc(IndexOutOfBoundsError)
	// NeedAttributeTranslatorError indicates a lack of object key translator (smallint|uint -> string).
	NeedAttributeTranslatorError = errors.New("need attribute translator")
	// IsNeedAttributeTranslator returns true if the given error is an NeedAttributeTranslatorError.
	IsNeedAttributeTranslator = isCausedByFunc(NeedAttributeTranslatorError)
	// InternalError indicates an error that the client cannot prevent.
	InternalError = errors.New("internal")
	// IsInternal returns true if the given error is an InternalError.
	IsInternal = isCausedByFunc(InternalError)
	// BuilderNeedOpenArrayError indicates an (invalid) attempt to open an array/object when that is not allowed.
	BuilderNeedOpenArrayError = errors.New("builder need open array")
	// IsBuilderNeedOpenArray returns true if the given error is an BuilderNeedOpenArrayError.
	IsBuilderNeedOpenArray = isCausedByFunc(BuilderNeedOpenArrayError)
	// BuilderNeedOpenObjectError indicates an (invalid) attempt to open an array/object when that is not allowed.
	BuilderNeedOpenObjectError = errors.New("builder need open object")
	// IsBuilderNeedOpenObject returns true if the given error is an BuilderNeedOpenObjectError.
	IsBuilderNeedOpenObject = isCausedByFunc(BuilderNeedOpenObjectError)
	// BuilderNeedOpenCompoundError indicates an (invalid) attempt to close an array/object that is already closed.
	BuilderNeedOpenCompoundError = errors.New("builder need open array or object")
	// IsBuilderNeedOpenCompound returns true if the given error is an BuilderNeedOpenCompoundError.
	IsBuilderNeedOpenCompound   = isCausedByFunc(BuilderNeedOpenCompoundError)
	DuplicateAttributeNameError = errors.New("duplicate key name")
	// IsDuplicateAttributeName returns true if the given error is an DuplicateAttributeNameError.
	IsDuplicateAttributeName = isCausedByFunc(DuplicateAttributeNameError)
	// BuilderNotClosedError is returned when a call is made to Builder.Bytes without being closed.
	BuilderNotClosedError = errors.New("builder not closed")
	// IsBuilderNotClosed returns true if the given error is an BuilderNotClosedError.
	IsBuilderNotClosed = isCausedByFunc(BuilderNotClosedError)
	// BuilderKeyAlreadyWrittenError is returned when a call is made to Builder.Bytes without being closed.
	BuilderKeyAlreadyWrittenError = errors.New("builder key already written")
	// IsBuilderKeyAlreadyWritten returns true if the given error is an BuilderKeyAlreadyWrittenError.
	IsBuilderKeyAlreadyWritten = isCausedByFunc(BuilderKeyAlreadyWrittenError)
	// BuilderKeyMustBeStringError is returned when a key is not of type string.
	BuilderKeyMustBeStringError = errors.New("builder key must be string")
	// IsBuilderKeyMustBeString returns true if the given error is an BuilderKeyMustBeStringError.
	IsBuilderKeyMustBeString = isCausedByFunc(BuilderKeyMustBeStringError)
	// BuilderNeedSubValueError is returned when a RemoveLast is called without any value in an object/array.
	BuilderNeedSubValueError = errors.New("builder need sub value")
	// IsBuilderNeedSubValue returns true if the given error is an BuilderNeedSubValueError.
	IsBuilderNeedSubValue = isCausedByFunc(BuilderNeedSubValueError)
	// InvalidUtf8SequenceError indicates an invalid UTF8 (string) sequence.
	InvalidUtf8SequenceError = errors.New("invalid utf8 sequence")
	// IsInvalidUtf8Sequence returns true if the given error is an InvalidUtf8SequenceError.
	IsInvalidUtf8Sequence = isCausedByFunc(InvalidUtf8SequenceError)
	// NoJSONEquivalentError is returned when a Velocypack type cannot be converted to JSON.
	NoJSONEquivalentError = errors.New("no JSON equivalent")
	// IsNoJSONEquivalent returns true if the given error is an NoJSONEquivalentError.
	IsNoJSONEquivalent = isCausedByFunc(NoJSONEquivalentError)
)
View Source
var (
	// WithStack is called on every return of an error to add stacktrace information to the error.
	// When setting this function, also set the Cause function.
	// The interface of this function is compatible with functions in github.com/pkg/errors.
	// WithStack(nil) must return nil.
	WithStack = func(err error) error { return err }
	// Cause is used to get the root cause of the given error.
	// The interface of this function is compatible with functions in github.com/pkg/errors.
	// Cause(nil) must return nil.
	Cause = func(err error) error { return err }
)

Functions

func IsBuilderUnexpectedType

func IsBuilderUnexpectedType(err error) bool

IsBuilderUnexpectedType returns true if the given error is an BuilderUnexpectedTypeError.

func IsInvalidType

func IsInvalidType(err error) bool

IsInvalidType returns true if the given error is an InvalidTypeError.

func IsInvalidUnmarshal

func IsInvalidUnmarshal(err error) bool

IsInvalidUnmarshal returns true if the given error is an InvalidUnmarshalError.

func IsMarshaler

func IsMarshaler(err error) bool

IsMarshaler returns true if the given error is an MarshalerError.

func IsParse

func IsParse(err error) bool

IsParse returns true if the given error is a ParseError.

func IsUnmarshalType

func IsUnmarshalType(err error) bool

IsUnmarshalType returns true if the given error is an UnmarshalTypeError.

func IsUnsupportedType

func IsUnsupportedType(err error) bool

IsUnsupportedType returns true if the given error is an UnsupportedTypeError.

func Unmarshal

func Unmarshal(data Slice, v interface{}) error

Unmarshal reads v from the given Velocypack encoded data slice.

Unmarshal uses the inverse of the encodings that Marshal uses, allocating maps, slices, and pointers as necessary, with the following additional rules:

To unmarshal VelocyPack into a pointer, Unmarshal first handles the case of the VelocyPack being the VelocyPack literal Null. In that case, Unmarshal sets the pointer to nil. Otherwise, Unmarshal unmarshals the VelocyPack into the value pointed at by the pointer. If the pointer is nil, Unmarshal allocates a new value for it to point to.

To unmarshal VelocyPack into a value implementing the Unmarshaler interface, Unmarshal calls that value's UnmarshalVPack method, including when the input is a VelocyPack Null. Otherwise, if the value implements encoding.TextUnmarshaler and the input is a VelocyPack quoted string, Unmarshal calls that value's UnmarshalText method with the unquoted form of the string.

To unmarshal VelocyPack into a struct, Unmarshal matches incoming object keys to the keys used by Marshal (either the struct field name or its tag), preferring an exact match but also accepting a case-insensitive match. Unmarshal will only set exported fields of the struct.

To unmarshal VelocyPack into an interface value, Unmarshal stores one of these in the interface value:

bool, for VelocyPack Bool's
float64 for VelocyPack Double's
uint64 for VelocyPack UInt's
int64 for VelocyPack Int's
string, for VelocyPack String's
[]interface{}, for VelocyPack Array's
map[string]interface{}, for VelocyPack Object's
nil for VelocyPack Null.
[]byte for VelocyPack Binary.

To unmarshal a VelocyPack array into a slice, Unmarshal resets the slice length to zero and then appends each element to the slice. As a special case, to unmarshal an empty VelocyPack array into a slice, Unmarshal replaces the slice with a new empty slice.

To unmarshal a VelocyPack array into a Go array, Unmarshal decodes VelocyPack array elements into corresponding Go array elements. If the Go array is smaller than the VelocyPack array, the additional VelocyPack array elements are discarded. If the VelocyPack array is smaller than the Go array, the additional Go array elements are set to zero values.

To unmarshal a VelocyPack object into a map, Unmarshal first establishes a map to use. If the map is nil, Unmarshal allocates a new map. Otherwise Unmarshal reuses the existing map, keeping existing entries. Unmarshal then stores key-value pairs from the VelocyPack object into the map. The map's key type must either be a string, an integer, or implement encoding.TextUnmarshaler.

If a VelocyPack value is not appropriate for a given target type, or if a VelocyPack number overflows the target type, Unmarshal skips that field and completes the unmarshaling as best it can. If no more serious errors are encountered, Unmarshal returns an UnmarshalTypeError describing the earliest such error.

The VelocyPack Null value unmarshals into an interface, map, pointer, or slice by setting that Go value to nil. Because null is often used in VelocyPack to mean “not present,” unmarshaling a VelocyPack Null into any other Go type has no effect on the value and produces no error.

Types

type ArrayIterator

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

func NewArrayIterator

func NewArrayIterator(s Slice) (*ArrayIterator, error)

NewArrayIterator initializes an iterator at position 0 of the given object slice.

func (*ArrayIterator) IsFirst

func (i *ArrayIterator) IsFirst() bool

IsFirst returns true if the current position is 0.

func (*ArrayIterator) IsValid

func (i *ArrayIterator) IsValid() bool

IsValid returns true if the given position of the iterator is valid.

func (*ArrayIterator) Next

func (i *ArrayIterator) Next() error

Next moves to the next position.

func (*ArrayIterator) Value

func (i *ArrayIterator) Value() (Slice, error)

Value returns the value of the current position of the iterator

type Builder

type Builder struct {
	BuilderOptions
	// contains filtered or unexported fields
}

Builder is used to build VPack structures.

func NewBuilder

func NewBuilder(capacity uint) *Builder

func (*Builder) Add

func (b *Builder) Add(v interface{}) error

Add adds a raw go value value to an array/raw value/object.

func (*Builder) AddKeyValue

func (b *Builder) AddKeyValue(key string, v Value) error

AddKeyValue adds a key+value to an open object.

func (*Builder) AddKeyValuesFromIterator

func (b *Builder) AddKeyValuesFromIterator(it *ObjectIterator) error

AddKeyValuesFromIterator adds values to an object from the given iterator. The object must be opened before a call to this function and the object is left open Intentionally.

func (*Builder) AddValue

func (b *Builder) AddValue(v Value) error

AddValue adds a value to an array/raw value/object.

func (*Builder) AddValuesFromIterator

func (b *Builder) AddValuesFromIterator(it *ArrayIterator) error

AddValuesFromIterator adds values to an array from the given iterator. The array must be opened before a call to this function and the array is left open Intentionally.

func (*Builder) Bytes

func (b *Builder) Bytes() ([]byte, error)

Bytes return the generated bytes. The returned slice is shared with the builder itself, so you must not modify it. When the builder is not closed, an error is returned.

func (*Builder) Clear

func (b *Builder) Clear()

Clear and start from scratch:

func (*Builder) Close

func (b *Builder) Close() error

Close ends an open object or array.

func (*Builder) GetKey

func (b *Builder) GetKey(key string) (Slice, error)

GetKey returns the value for a specific key of an Object value. Returns Slice of type None when key is not found.

func (*Builder) HasKey

func (b *Builder) HasKey(key string) (bool, error)

HasKey checks whether an Object value has a specific key attribute.

func (*Builder) IsClosed

func (b *Builder) IsClosed() bool

IsClosed returns true if there are no more open objects or arrays.

func (*Builder) IsEmpty

func (b *Builder) IsEmpty() bool

IsEmpty returns true when no bytes have been generated yet.

func (*Builder) IsOpenArray

func (b *Builder) IsOpenArray() bool

IsOpenArray returns true when the builder has an open array at the top of the stack.

func (*Builder) IsOpenObject

func (b *Builder) IsOpenObject() bool

IsOpenObject returns true when the builder has an open object at the top of the stack.

func (*Builder) OpenArray

func (b *Builder) OpenArray(unindexed ...bool) error

OpenArray starts a new array. This must be closed using Close.

func (*Builder) OpenObject

func (b *Builder) OpenObject(unindexed ...bool) error

OpenObject starts a new object. This must be closed using Close.

func (*Builder) RemoveLast

func (b *Builder) RemoveLast() error

RemoveLast removes last subvalue written to an (unclosed) object or array.

func (*Builder) Size

func (b *Builder) Size() (ValueLength, error)

Size returns the actual size of the generated slice. Returns an error when builder is not closed.

func (*Builder) Slice

func (b *Builder) Slice() (Slice, error)

Slice returns a slice of the result.

func (*Builder) WriteTo

func (b *Builder) WriteTo(w io.Writer) (int64, error)

WriteTo writes the generated bytes to the given writer. When the builder is not closed, an error is returned.

type BuilderOptions

type BuilderOptions struct {
	BuildUnindexedArrays     bool
	BuildUnindexedObjects    bool
	CheckAttributeUniqueness bool
}

BuilderOptions contains options that influence how Builder builds slices.

type BuilderUnexpectedTypeError

type BuilderUnexpectedTypeError struct {
	Message string
}

BuilderUnexpectedTypeError is returned when a Builder function received an invalid type.

func (BuilderUnexpectedTypeError) Error

Error implements the error interface for BuilderUnexpectedTypeError.

type Decoder

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

A Decoder decodes velocypack values into Go structures.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder creates a new Decoder that reads data from the given reader.

func (*Decoder) Decode

func (e *Decoder) Decode(v interface{}) error

Decode reads v from the decoder stream.

type Dumper

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

func NewDumper

func NewDumper(w io.Writer, options *DumperOptions) *Dumper

NewDumper creates a new dumper around the given writer, with an optional options.

func (*Dumper) Append

func (d *Dumper) Append(s Slice) error

type DumperOptions

type DumperOptions struct {
	// EscapeUnicode turns on escapping multi-byte Unicode characters when dumping them to JSON (creates \uxxxx sequences).
	EscapeUnicode bool
	// EscapeForwardSlashes turns on escapping forward slashes when serializing VPack values into JSON.
	EscapeForwardSlashes    bool
	UnsupportedTypeBehavior UnsupportedTypeBehavior
}

type Encoder

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

An Encoder encodes Go structures into velocypack values written to an output stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder creates a new Encoder that writes output to the given writer.

func (*Encoder) Builder

func (e *Encoder) Builder() *Builder

Builder returns a reference to the builder used in the given encoder.

func (*Encoder) Encode

func (e *Encoder) Encode(v interface{}) (err error)

Encode writes the Velocypack encoding of v to the stream.

type InvalidTypeError

type InvalidTypeError struct {
	Message string
}

InvalidTypeError is returned when a Slice getter is called on a slice of a different type.

func (InvalidTypeError) Error

func (e InvalidTypeError) Error() string

Error implements the error interface for InvalidTypeError.

type InvalidUnmarshalError

type InvalidUnmarshalError struct {
	Type reflect.Type
}

An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. (The argument to Unmarshal must be a non-nil pointer.)

func (*InvalidUnmarshalError) Error

func (e *InvalidUnmarshalError) Error() string

type Marshaler

type Marshaler interface {
	MarshalVPack() (Slice, error)
}

Marshaler is implemented by types that can convert themselves into Velocypack.

type MarshalerError

type MarshalerError struct {
	Type reflect.Type
	Err  error
}

MarshalerError is returned when a custom VPack Marshaler returns an error.

func (MarshalerError) Error

func (e MarshalerError) Error() string

Error implements the error interface for MarshalerError.

type ObjectIterator

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

func NewObjectIterator

func NewObjectIterator(s Slice, allowRandomIteration ...bool) (*ObjectIterator, error)

NewObjectIterator initializes an iterator at position 0 of the given object slice.

func (*ObjectIterator) IsFirst

func (i *ObjectIterator) IsFirst() bool

IsFirst returns true if the current position is 0.

func (*ObjectIterator) IsValid

func (i *ObjectIterator) IsValid() bool

IsValid returns true if the given position of the iterator is valid.

func (*ObjectIterator) Key

func (i *ObjectIterator) Key(translate bool) (Slice, error)

Key returns the key of the current position of the iterator

func (*ObjectIterator) Next

func (i *ObjectIterator) Next() error

Next moves to the next position.

func (*ObjectIterator) Value

func (i *ObjectIterator) Value() (Slice, error)

Value returns the value of the current position of the iterator

type ParseError

type ParseError struct {
	Offset int64
	// contains filtered or unexported fields
}

An ParseError is returned when JSON cannot be parsed correctly.

func (*ParseError) Error

func (e *ParseError) Error() string

type Parser

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

Parser is used to build VPack structures from JSON.

func NewParser

func NewParser(r io.Reader, builder *Builder, options ...ParserOptions) *Parser

NewParser initializes a new Parser with JSON from the given reader and it will store the parsers output in the given builder.

func (*Parser) Parse

func (p *Parser) Parse() error

Parse JSON from the parsers reader and build VPack structures in the parsers builder.

type ParserOptions

type ParserOptions struct {
	// If set, all Array's will be unindexed.
	BuildUnindexedArrays bool
	// If set, all Objects's will be unindexed.
	BuildUnindexedObjects bool
}

ParserOptions controls how the Parser builds Velocypack.

type RawSlice

type RawSlice []byte

RawSlice is a raw encoded Velocypack value. It implements Marshaler and Unmarshaler and can be used to delay Velocypack decoding or precompute a Velocypack encoding.

func (RawSlice) MarshalVPack

func (m RawSlice) MarshalVPack() (Slice, error)

MarshalVPack returns m as the Velocypack encoding of m.

func (*RawSlice) UnmarshalVPack

func (m *RawSlice) UnmarshalVPack(data Slice) error

UnmarshalVPack sets *m to a copy of data.

type Slice

type Slice []byte

Slice provides read only access to a VPack value

func EmptyArraySlice

func EmptyArraySlice() Slice

EmptyArraySlice creates a slice of type Array, empty

func EmptyObjectSlice

func EmptyObjectSlice() Slice

EmptyObjectSlice creates a slice of type Object, empty

func FalseSlice

func FalseSlice() Slice

FalseSlice creates a slice of type Boolean with false value

func IllegalSlice

func IllegalSlice() Slice

IllegalSlice creates a slice of type Illegal

func Marshal

func Marshal(v interface{}) (result Slice, err error)

Marshal writes the Velocypack encoding of v to a buffer and returns that buffer.

Marshal traverses the value v recursively. If an encountered value implements the Marshaler interface and is not a nil pointer, Marshal calls its MarshalVPack method to produce Velocypack. If an encountered value implements the json.Marshaler interface and is not a nil pointer, Marshal calls its MarshalJSON method to produce JSON and converts the resulting JSON to VelocyPack. If no MarshalVPack or MarshalJSON method is present but the value implements encoding.TextMarshaler instead, Marshal calls its MarshalText method and encodes the result as a Velocypack string. The nil pointer exception is not strictly necessary but mimics a similar, necessary exception in the behavior of UnmarshalVPack.

Otherwise, Marshal uses the following type-dependent default encodings:

Boolean values encode as Velocypack booleans.

Floating point, integer, and Number values encode as Velocypack Int's, UInt's and Double's.

String values encode as Velocypack strings.

Array and slice values encode as Velocypack arrays, except that []byte encodes as Velocypack Binary data, and a nil slice encodes as the Null Velocypack value.

Struct values encode as Velocypack objects. The encoding follows the same rules as specified for json.Marshal. This means that all `json` tags are fully supported.

Map values encode as Velocypack objects. The encoding follows the same rules as specified for json.Marshal.

Pointer values encode as the value pointed to. A nil pointer encodes as the Null Velocypack value.

Interface values encode as the value contained in the interface. A nil interface value encodes as the Null Velocypack value.

Channel, complex, and function values cannot be encoded in Velocypack. Attempting to encode such a value causes Marshal to return an UnsupportedTypeError.

Velocypack cannot represent cyclic data structures and Marshal does not handle them. Passing cyclic structures to Marshal will result in an infinite recursion.

func MaxKeySlice

func MaxKeySlice() Slice

MaxKeySlice creates a slice of type MaxKey

func Merge

func Merge(slices ...Slice) (Slice, error)

Merge creates a slice that contains all fields from all given slices. When a field exists (with same name) in an earlier slice, it is ignored. All slices must be objects.

func MinKeySlice

func MinKeySlice() Slice

MinKeySlice creates a slice of type MinKey

func NoneSlice

func NoneSlice() Slice

NoneSlice creates a slice of type None

func NullSlice

func NullSlice() Slice

NullSlice creates a slice of type Null

func ParseJSON

func ParseJSON(r io.Reader, options ...ParserOptions) (Slice, error)

ParseJSON parses JSON from the given reader and returns the VPack equivalent.

func ParseJSONFromString

func ParseJSONFromString(json string, options ...ParserOptions) (Slice, error)

ParseJSONFromString parses the given JSON string and returns the VPack equivalent.

func ParseJSONFromUTF8

func ParseJSONFromUTF8(json []byte, options ...ParserOptions) (Slice, error)

ParseJSONFromUTF8 parses the given JSON string and returns the VPack equivalent.

func SliceFromHex

func SliceFromHex(v string) Slice

SliceFromHex creates a Slice by decoding the given hex string into a Slice. If decoding fails, nil is returned.

func SliceFromReader

func SliceFromReader(r io.Reader) (Slice, error)

SliceFromReader reads a slice from the given reader.

func StringSlice

func StringSlice(s string) Slice

StringSlice creates a slice of type String with given string value

func TrueSlice

func TrueSlice() Slice

TrueSlice creates a slice of type Boolean with true value

func ZeroSlice

func ZeroSlice() Slice

ZeroSlice creates a slice of type Smallint(0)

func (Slice) AssertType

func (s Slice) AssertType(t ValueType) error

AssertType returns an error when the vpack type of the slice different from the given type. Returns nil otherwise.

func (Slice) AssertTypeAny

func (s Slice) AssertTypeAny(t ...ValueType) error

AssertTypeAny returns an error when the vpack type of the slice different from all of the given types. Returns nil otherwise.

func (Slice) At

func (s Slice) At(index ValueLength) (Slice, error)

At extracts the array value at the specified index.

func (Slice) ByteSize

func (s Slice) ByteSize() (ValueLength, error)

ByteSize returns the total byte size for the slice, including the head byte

func (Slice) CompareString

func (s Slice) CompareString(value string) (int, error)

CompareString compares the string value in the slice with the given string. s == value -> 0 s < value -> -1 s > value -> 1

func (Slice) Get

func (s Slice) Get(attributePath ...string) (Slice, error)

Get looks for the specified attribute path inside an Object returns a Slice(ValueType::None) if not found

func (Slice) GetBinary

func (s Slice) GetBinary() ([]byte, error)

GetBinary return the value for a Binary object

func (Slice) GetBinaryLength

func (s Slice) GetBinaryLength() (ValueLength, error)

GetBinaryLength return the length for a Binary object

func (Slice) GetBool

func (s Slice) GetBool() (bool, error)

GetBool returns a boolean value from the slice. Returns an error if slice is not of type Bool.

func (Slice) GetDouble

func (s Slice) GetDouble() (float64, error)

GetDouble returns a Double value from the slice. Returns an error if slice is not of type Double.

func (Slice) GetInt

func (s Slice) GetInt() (int64, error)

GetInt returns a Int value from the slice. Returns an error if slice is not of type Int.

func (Slice) GetSmallInt

func (s Slice) GetSmallInt() (int64, error)

GetSmallInt returns a SmallInt value from the slice. Returns an error if slice is not of type SmallInt.

func (Slice) GetString

func (s Slice) GetString() (string, error)

GetString return the value for a String object This function is a bit slower than GetStringUTF8, since the conversion from []byte to string needs a memory allocation.

func (Slice) GetStringLength

func (s Slice) GetStringLength() (ValueLength, error)

GetStringLength return the length for a String object

func (Slice) GetStringUTF8

func (s Slice) GetStringUTF8() ([]byte, error)

GetStringUTF8 return the value for a String object as a []byte with UTF-8 values. This function is a bit faster than GetString, since the conversion from []byte to string needs a memory allocation.

func (Slice) GetUInt

func (s Slice) GetUInt() (uint64, error)

GetUInt returns a UInt value from the slice. Returns an error if slice is not of type UInt.

func (Slice) GetUTCDate

func (s Slice) GetUTCDate() (time.Time, error)

GetUTCDate return the value for an UTCDate object

func (Slice) HasKey

func (s Slice) HasKey(keyPath ...string) (bool, error)

HasKey returns true if the slice is an object that has a given key path.

func (Slice) IsArray

func (s Slice) IsArray() bool

IsArray returns true if slice is an Array object

func (Slice) IsBCD

func (s Slice) IsBCD() bool

IsBCD returns true if slice is a BCD

func (Slice) IsBinary

func (s Slice) IsBinary() bool

IsBinary returns true if slice is a Binary object

func (Slice) IsBool

func (s Slice) IsBool() bool

IsBool returns true if slice is a Bool object

func (Slice) IsCustom

func (s Slice) IsCustom() bool

IsCustom returns true if slice is a Custom type

func (Slice) IsDouble

func (s Slice) IsDouble() bool

IsDouble returns true if slice is a Double object

func (Slice) IsEmptyArray

func (s Slice) IsEmptyArray() bool

IsEmptyArray tests whether the Slice is an empty array

func (Slice) IsEmptyObject

func (s Slice) IsEmptyObject() bool

IsEmptyObject tests whether the Slice is an empty object

func (Slice) IsEqualString

func (s Slice) IsEqualString(value string) (bool, error)

IsEqualString compares the string value in the slice with the given string for equivalence.

func (Slice) IsExternal

func (s Slice) IsExternal() bool

IsExternal returns true if slice is an External object

func (Slice) IsFalse

func (s Slice) IsFalse() bool

IsFalse returns true if slice is the Boolean value false

func (Slice) IsIllegal

func (s Slice) IsIllegal() bool

IsIllegal returns true if slice is an Illegal object

func (Slice) IsInt

func (s Slice) IsInt() bool

IsInt returns true if slice is an Int object

func (Slice) IsInteger

func (s Slice) IsInteger() bool

IsInteger returns true if a slice is any decimal number type

func (Slice) IsMaxKey

func (s Slice) IsMaxKey() bool

IsMaxKey returns true if slice is a MaxKey object

func (Slice) IsMinKey

func (s Slice) IsMinKey() bool

IsMinKey returns true if slice is a MinKey object

func (Slice) IsNone

func (s Slice) IsNone() bool

IsNone returns true if slice is a None object

func (Slice) IsNull

func (s Slice) IsNull() bool

IsNull returns true if slice is a Null object

func (Slice) IsNumber

func (s Slice) IsNumber() bool

IsNumber returns true if slice is any Number-type object

func (Slice) IsObject

func (s Slice) IsObject() bool

IsObject returns true if slice is an Object object

func (Slice) IsSmallInt

func (s Slice) IsSmallInt() bool

IsSmallInt returns true if slice is a SmallInt object

func (Slice) IsSorted

func (s Slice) IsSorted() bool

IsSorted returns true if slice is an object with table offsets, sorted by attribute name

func (Slice) IsString

func (s Slice) IsString() bool

IsString returns true if slice is a String object

func (Slice) IsTrue

func (s Slice) IsTrue() bool

IsTrue returns true if slice is the Boolean value true

func (Slice) IsType

func (s Slice) IsType(t ValueType) bool

IsType returns true when the vpack type of the slice is equal to the given type. Returns false otherwise.

func (Slice) IsUInt

func (s Slice) IsUInt() bool

IsUInt returns true if slice is a UInt object

func (Slice) IsUTCDate

func (s Slice) IsUTCDate() bool

IsUTCDate returns true if slice is a UTCDate object

func (Slice) JSONString

func (s Slice) JSONString(options ...DumperOptions) (string, error)

JSONString converts the contents of the slice to JSON.

func (Slice) KeyAt

func (s Slice) KeyAt(index ValueLength, translate ...bool) (Slice, error)

KeyAt extracts a key from an Object at the specified index.

func (Slice) Length

func (s Slice) Length() (ValueLength, error)

Length return the number of members for an Array or Object object

func (Slice) Next

func (s Slice) Next() (Slice, error)

Next returns the Slice that directly follows the given slice. Same as s[s.ByteSize:]

func (Slice) String

func (s Slice) String() string

String returns a HEX representation of the slice.

func (Slice) Type

func (s Slice) Type() ValueType

Type returns the vpack type of the slice

func (Slice) ValueAt

func (s Slice) ValueAt(index ValueLength) (Slice, error)

ValueAt extracts a value from an Object at the specified index

type UnmarshalTypeError

type UnmarshalTypeError struct {
	Value  string       // description of JSON value - "bool", "array", "number -5"
	Type   reflect.Type // type of Go value it could not be assigned to
	Struct string       // name of the struct type containing the field
	Field  string       // name of the field holding the Go value
}

An UnmarshalTypeError describes a JSON value that was not appropriate for a value of a specific Go type.

func (*UnmarshalTypeError) Error

func (e *UnmarshalTypeError) Error() string

type Unmarshaler

type Unmarshaler interface {
	UnmarshalVPack(Slice) error
}

Unmarshaler is implemented by types that can convert themselves from Velocypack.

type UnsupportedTypeBehavior

type UnsupportedTypeBehavior int
const (
	NullifyUnsupportedType UnsupportedTypeBehavior = iota
	ConvertUnsupportedType
	FailOnUnsupportedType
)

type UnsupportedTypeError

type UnsupportedTypeError struct {
	Type reflect.Type
}

UnsupportedTypeError is returned when a type is marshaled that cannot be marshaled.

func (UnsupportedTypeError) Error

func (e UnsupportedTypeError) Error() string

Error implements the error interface for UnsupportedTypeError.

type Value

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

Value is a helper structure used to build VPack structures. It holds a single data value with a specific type.

func NewArrayValue

func NewArrayValue(unindexed ...bool) Value

NewArrayValue creates a new Value that opens a new array.

func NewBinaryValue

func NewBinaryValue(value []byte) Value

NewBinaryValue creates a new Value of type Binary with given value.

func NewBoolValue

func NewBoolValue(value bool) Value

NewBoolValue creates a new Value of type Bool with given value.

func NewDoubleValue

func NewDoubleValue(value float64) Value

NewDoubleValue creates a new Value of type Double with given value.

func NewIntValue

func NewIntValue(value int64) Value

NewIntValue creates a new Value of type Int with given value.

func NewMaxKeyValue

func NewMaxKeyValue() Value

NewMaxKeyValue creates a new Value of type MaxKey.

func NewMinKeyValue

func NewMinKeyValue() Value

NewMinKeyValue creates a new Value of type MinKey.

func NewNullValue

func NewNullValue() Value

NewNullValue creates a new Value of type Null.

func NewObjectValue

func NewObjectValue(unindexed ...bool) Value

NewObjectValue creates a new Value that opens a new object.

func NewReflectValue

func NewReflectValue(v reflect.Value) Value

NewReflectValue creates a new Value with type derived from Go type of given reflect value. If the given value is not a supported type, a Value of type Illegal is returned.

func NewSliceValue

func NewSliceValue(value Slice) Value

NewSliceValue creates a new Value of from the given slice.

func NewStringValue

func NewStringValue(value string) Value

NewStringValue creates a new Value of type String with given value.

func NewUIntValue

func NewUIntValue(value uint64) Value

NewUIntValue creates a new Value of type UInt with given value.

func NewUTCDateValue

func NewUTCDateValue(value time.Time) Value

NewUTCDateValue creates a new Value of type UTCDate with given value.

func NewValue

func NewValue(value interface{}) Value

NewValue creates a new Value with type derived from Go type of given value. If the given value is not a supported type, a Value of type Illegal is returned.

func (Value) IsIllegal

func (v Value) IsIllegal() bool

IsIllegal returns true if the type of value is Illegal.

func (Value) IsSlice

func (v Value) IsSlice() bool

IsSlice returns true when the value already contains a slice.

func (Value) Type

func (v Value) Type() ValueType

Type returns the ValueType of this value.

type ValueLength

type ValueLength uint64

func (ValueLength) String

func (s ValueLength) String() string

type ValueType

type ValueType int
const (
	None    ValueType = iota // not yet initialized
	Illegal                  // illegal value
	Null                     // JSON null
	Bool
	Array
	Object
	Double
	UTCDate
	External
	MinKey
	MaxKey
	Int
	UInt
	SmallInt
	String
	Binary
	BCD
	Custom
)

func (ValueType) String

func (vt ValueType) String() string

String returns a string representation of the given type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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