vals

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const NumDatatypes = 8

NumDatatypes is the total count of data types, including unknown type

Variables

This section is empty.

Functions

func CompareIntegerBytes

func CompareIntegerBytes(a, b []byte) (int, error)

CompareIntegerBytes compares two byte slices of interger data

func CompareNumberBytes

func CompareNumberBytes(a, b []byte) (int, error)

CompareNumberBytes compares two byte slices of float data

func CompareTypeBytes

func CompareTypeBytes(a, b []byte, t Type) (int, error)

CompareTypeBytes compares two byte slices with a known type real on the real, this is a bit of a work in progress TODO - up tests

func Equal

func Equal(a, b Value) bool

Equal checks if two Values are the same

func IsBoolean

func IsBoolean(value []byte) bool

IsBoolean checks if a slice of bytes is a boolean value

func IsFloat

func IsFloat(value []byte) bool

IsFloat checks if a slice of bytes is a float value

func IsInteger

func IsInteger(value []byte) bool

IsInteger checks if a slice of bytes is an integer

func JSONArrayOrObject

func JSONArrayOrObject(value []byte) string

JSONArrayOrObject examines bytes checking if the outermost closure is an array or object

func ParseBoolean

func ParseBoolean(value []byte) (bool, error)

ParseBoolean converts raw bytes to a bool value

func ParseInteger

func ParseInteger(value []byte) (int64, error)

ParseInteger converts raw bytes to a int64 value

func ParseJSON

func ParseJSON(value []byte) (interface{}, error)

ParseJSON converts raw bytes to a JSON value

func ParseNumber

func ParseNumber(value []byte) (float64, error)

ParseNumber converts raw bytes to a float64 value

func ParseString

func ParseString(value []byte) (string, error)

ParseString converts raw bytes to a string value

Types

type Array

type Array []Value

Array is an ordered list of Values

func (Array) Boolean

func (a Array) Boolean() bool

Boolean of Array will always panic

func (Array) Index

func (a Array) Index(i int) Value

Index gives the value of a slice index

func (Array) Integer

func (a Array) Integer() int

Integer of Array will always panic

func (Array) IsNull

func (a Array) IsNull() bool

IsNull of Array always returns false

func (Array) Keys

func (a Array) Keys() []string

Keys of Array will always panic

func (Array) Len

func (a Array) Len() int

Len returns the length of the array

func (Array) MapIndex

func (a Array) MapIndex(key string) Value

MapIndex of Array will always Panic

func (Array) Number

func (a Array) Number() float64

Number of Array will always panic

func (Array) String

func (a Array) String() string

String of Array must satisfy the stringer interface, but output is intentionally obfuscated

func (Array) Type

func (a Array) Type() Type

Type Notifies others this is of Array type

type Boolean

type Boolean bool

Boolean represents true/false values

func (Boolean) Boolean

func (b Boolean) Boolean() bool

Boolean returns Boolean as a bool

func (Boolean) Index

func (b Boolean) Index(i int) Value

Index of Boolean will always panic

func (Boolean) Integer

func (b Boolean) Integer() int

Integer of Boolean will always panic

func (Boolean) IsNull

func (b Boolean) IsNull() bool

IsNull of Boolean always returns false

func (Boolean) Keys

func (b Boolean) Keys() []string

Keys of Boolean will always panic

func (Boolean) Len

func (b Boolean) Len() int

Len of Boolean will always panic

func (Boolean) MapIndex

func (b Boolean) MapIndex(key string) Value

MapIndex of Boolean will always Panic

func (Boolean) Number

func (b Boolean) Number() float64

Number of Boolean will always panic

func (Boolean) String

func (b Boolean) String() string

String of Boolean must satisfy the stringer interface, but output is intentionally obfuscated

func (Boolean) Type

func (b Boolean) Type() Type

Type declares this value is of Boolean type

type Integer

type Integer int

Integer represents a whole number

func (Integer) Boolean

func (i Integer) Boolean() bool

Boolean of Integer will always panic

func (Integer) Index

func (i Integer) Index(j int) Value

Index of Integer will always panic

func (Integer) Integer

func (i Integer) Integer() int

Integer returns this number formatted as an int

func (Integer) IsNull

func (i Integer) IsNull() bool

IsNull of Integer always returns false

func (Integer) Keys

func (i Integer) Keys() []string

Keys of Integer will always panic

func (Integer) Len

func (i Integer) Len() int

Len of Integer will always panic

func (Integer) MapIndex

func (i Integer) MapIndex(key string) Value

MapIndex of Integer will always Panic

func (Integer) Number

func (i Integer) Number() float64

Number of Integer returns int formatted as a float64

func (Integer) String

func (i Integer) String() string

String of Integer must satisfy the stringer interface, but output is intentionally obfuscated

func (Integer) Type

func (i Integer) Type() Type

Type declares this value is of Integer type

type Null

type Null bool

Null represents explicit null values

func (Null) Boolean

func (n Null) Boolean() bool

Boolean of Null will always panic

func (Null) Index

func (n Null) Index(i int) Value

Index of Null will always panic

func (Null) Integer

func (n Null) Integer() int

Integer of Null will always panic

func (Null) IsNull

func (n Null) IsNull() bool

IsNull of Null always returns true

func (Null) Keys

func (n Null) Keys() []string

Keys of Null will always panic

func (Null) Len

func (n Null) Len() int

Len of Null will always panic

func (Null) MapIndex

func (n Null) MapIndex(key string) Value

MapIndex of Null will always Panic

func (Null) MarshalJSON

func (n Null) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for Null

func (Null) Number

func (n Null) Number() float64

Number of Null will always panic

func (Null) String

func (n Null) String() string

String of Null must satisfy the stringer interface, but output is intentionally obfuscated

func (Null) Type

func (n Null) Type() Type

Type declares this value is of Null type

type Number

type Number float64

Number represents a floating point number

func (Number) Boolean

func (n Number) Boolean() bool

Boolean of Number will always panic

func (Number) Index

func (n Number) Index(i int) Value

Index of Number will always panic

func (Number) Integer

func (n Number) Integer() int

Integer of Number will always panic TODO - should we allow this? rounding is nice. maybe.

func (Number) IsNull

func (n Number) IsNull() bool

IsNull of Number always returns false

func (Number) Keys

func (n Number) Keys() []string

Keys of Number will always panic

func (Number) Len

func (n Number) Len() int

Len of Number will always panic

func (Number) MapIndex

func (n Number) MapIndex(key string) Value

MapIndex of Number will always Panic

func (Number) Number

func (n Number) Number() float64

Number returns Number as a float64

func (Number) String

func (n Number) String() string

String of Number must satisfy the stringer interface, but output is intentionally obfuscated

func (Number) Type

func (n Number) Type() Type

Type declares this value is of Number type

type Object

type Object map[string]Value

Object represents an object value

func (Object) Boolean

func (o Object) Boolean() bool

Boolean of an Object will always panic

func (Object) Index

func (o Object) Index(i int) Value

Index of an Object will always panic

func (Object) Integer

func (o Object) Integer() int

Integer of an Object will always panic

func (Object) IsNull

func (o Object) IsNull() bool

IsNull of an Object always returns false

func (Object) Keys

func (o Object) Keys() (keys []string)

Keys gives a slice of keys in an object, in random order

func (Object) Len

func (o Object) Len() int

Len of an Object will always panic

func (Object) MapIndex

func (o Object) MapIndex(key string) Value

MapIndex Gives an element for a map key

func (Object) Number

func (o Object) Number() float64

Number of an Object will always panic

func (Object) String

func (o Object) String() string

String must satisfy the stringer interface, but output is intentionally obfuscated

func (Object) Type

func (o Object) Type() Type

Type yields one of the primitive types

type ObjectValue

type ObjectValue struct {
	Key string
	Value
}

ObjectValue is a special value that represents a value in the context of a parent object It wraps a value, adding a property "Key" that holds the value's key in the parent object

type String

type String string

String represents a string value

func (String) Boolean

func (s String) Boolean() bool

Boolean of String will always panic

func (String) Index

func (s String) Index(i int) Value

Index of String will always panic

func (String) Integer

func (s String) Integer() int

Integer of String will always panic

func (String) IsNull

func (s String) IsNull() bool

IsNull of String always returns false

func (String) Keys

func (s String) Keys() []string

Keys of String will always panic

func (String) Len

func (s String) Len() int

Len of String will always panic

func (String) MapIndex

func (s String) MapIndex(key string) Value

MapIndex of String will always Panic

func (String) Number

func (s String) Number() float64

Number of String will always panic

func (String) String

func (s String) String() string

String returns String as a string Say string one more time. I dare you. ... string

func (String) Type

func (s String) Type() Type

Type declares this value is of String type

type Type

type Type uint8

Type is a type of data, these types follow JSON type primitives, with an added type for whole numbers (integer)

const (
	// TypeUnknown is the default datatype, making for easier
	// errors when a datatype is expected
	TypeUnknown Type = iota
	// TypeNull specifies the null type
	TypeNull
	// TypeInteger specifies whole numbers
	TypeInteger
	// TypeNumber specifies numbers with decimal value
	TypeNumber
	// TypeBoolean species true/false values
	TypeBoolean
	// TypeString speficies text values
	TypeString
	// TypeObject maps string keys to values
	TypeObject
	// TypeArray is an ordered list of values
	TypeArray
	// TypeBytes is an ordered slice of bytes
	TypeBytes
)

func ParseType

func ParseType(value []byte) Type

ParseType examines a slice of bytes & attempts to determine it's type, starting with the more specific possible types, then falling back to more general types. ParseType always returns a type

func TypeFromString

func TypeFromString(t string) Type

TypeFromString takes a string & tries to return it's type defaulting to unknown if the type is unrecognized

func (Type) MarshalJSON

func (dt Type) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler on Type

func (Type) Parse

func (dt Type) Parse(value []byte) (parsed interface{}, err error)

Parse turns raw byte slices into data formatted according to the type receiver

func (Type) String

func (dt Type) String() string

String satsfies the stringer interface

func (*Type) UnmarshalJSON

func (dt *Type) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler on Type

func (Type) ValueToBytes

func (dt Type) ValueToBytes(value interface{}) (data []byte, err error)

ValueToBytes takes already-parsed values & converts them to a slice of bytes

func (Type) ValueToString

func (dt Type) ValueToString(value interface{}) (str string, err error)

ValueToString takes already-parsed values & converts them to a string

type Value

type Value interface {
	// Type yields one of the primitive types
	Type() Type

	// Number of elements if array type
	Len() int
	// Give element of a slice index
	Index(i int) Value

	// Slice of keys in an object, in random order
	Keys() []string
	// MapIndex returns the element stored at a string key
	MapIndex(key string) Value

	// Boolean value
	Boolean() bool
	// String value
	String() string
	// Int value
	Integer() int
	// Number value
	Number() float64
	// returns if the value is set to null
	IsNull() bool
}

Value represents a single data point of one of seven primitive types: null, boolean, string, integer, number, object, array

func ConvertDecoded

func ConvertDecoded(d interface{}) (Value, error)

ConvertDecoded converts an interface that has been decoded into standard go types to a Value

func NewObjectValue

func NewObjectValue(key string, v Value) Value

NewObjectValue allocates a new Object Value

func UnmarshalJSON

func UnmarshalJSON(data []byte) (v Value, err error)

UnmarshalJSON turns a slice of JSON bytes into a Value

type ValueError

type ValueError struct {
	Method string
	Type   Type
}

A ValueError occurs when a Value method is invoked on a Value that does not support it. Such cases are documented in the description of each method.

func (*ValueError) Error

func (e *ValueError) Error() string

Error implements the error interface

Jump to

Keyboard shortcuts

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