Documentation ¶
Index ¶
- Constants
- func CompareIntegerBytes(a, b []byte) (int, error)
- func CompareNumberBytes(a, b []byte) (int, error)
- func CompareTypeBytes(a, b []byte, t Type) (int, error)
- func Equal(a, b Value) bool
- func IsBoolean(value []byte) bool
- func IsFloat(value []byte) bool
- func IsInteger(value []byte) bool
- func JSONArrayOrObject(value []byte) string
- func ParseBoolean(value []byte) (bool, error)
- func ParseInteger(value []byte) (int64, error)
- func ParseJSON(value []byte) (interface{}, error)
- func ParseNumber(value []byte) (float64, error)
- func ParseString(value []byte) (string, error)
- type Array
- func (a Array) Boolean() bool
- func (a Array) Index(i int) Value
- func (a Array) Integer() int
- func (a Array) IsNull() bool
- func (a Array) Keys() []string
- func (a Array) Len() int
- func (a Array) MapIndex(key string) Value
- func (a Array) Number() float64
- func (a Array) String() string
- func (a Array) Type() Type
- type Boolean
- func (b Boolean) Boolean() bool
- func (b Boolean) Index(i int) Value
- func (b Boolean) Integer() int
- func (b Boolean) IsNull() bool
- func (b Boolean) Keys() []string
- func (b Boolean) Len() int
- func (b Boolean) MapIndex(key string) Value
- func (b Boolean) Number() float64
- func (b Boolean) String() string
- func (b Boolean) Type() Type
- type Integer
- func (i Integer) Boolean() bool
- func (i Integer) Index(j int) Value
- func (i Integer) Integer() int
- func (i Integer) IsNull() bool
- func (i Integer) Keys() []string
- func (i Integer) Len() int
- func (i Integer) MapIndex(key string) Value
- func (i Integer) Number() float64
- func (i Integer) String() string
- func (i Integer) Type() Type
- type Null
- func (n Null) Boolean() bool
- func (n Null) Index(i int) Value
- func (n Null) Integer() int
- func (n Null) IsNull() bool
- func (n Null) Keys() []string
- func (n Null) Len() int
- func (n Null) MapIndex(key string) Value
- func (n Null) MarshalJSON() ([]byte, error)
- func (n Null) Number() float64
- func (n Null) String() string
- func (n Null) Type() Type
- type Number
- func (n Number) Boolean() bool
- func (n Number) Index(i int) Value
- func (n Number) Integer() int
- func (n Number) IsNull() bool
- func (n Number) Keys() []string
- func (n Number) Len() int
- func (n Number) MapIndex(key string) Value
- func (n Number) Number() float64
- func (n Number) String() string
- func (n Number) Type() Type
- type Object
- func (o Object) Boolean() bool
- func (o Object) Index(i int) Value
- func (o Object) Integer() int
- func (o Object) IsNull() bool
- func (o Object) Keys() (keys []string)
- func (o Object) Len() int
- func (o Object) MapIndex(key string) Value
- func (o Object) Number() float64
- func (o Object) String() string
- func (o Object) Type() Type
- type ObjectValue
- type String
- func (s String) Boolean() bool
- func (s String) Index(i int) Value
- func (s String) Integer() int
- func (s String) IsNull() bool
- func (s String) Keys() []string
- func (s String) Len() int
- func (s String) MapIndex(key string) Value
- func (s String) Number() float64
- func (s String) String() string
- func (s String) Type() Type
- type Type
- func (dt Type) MarshalJSON() ([]byte, error)
- func (dt Type) Parse(value []byte) (parsed interface{}, err error)
- func (dt Type) String() string
- func (dt *Type) UnmarshalJSON(data []byte) error
- func (dt Type) ValueToBytes(value interface{}) (data []byte, err error)
- func (dt Type) ValueToString(value interface{}) (str string, err error)
- type Value
- type ValueError
Constants ¶
const NumDatatypes = 8
NumDatatypes is the total count of data types, including unknown type
Variables ¶
This section is empty.
Functions ¶
func CompareIntegerBytes ¶
CompareIntegerBytes compares two byte slices of interger data
func CompareNumberBytes ¶
CompareNumberBytes compares two byte slices of float data
func CompareTypeBytes ¶
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 JSONArrayOrObject ¶
JSONArrayOrObject examines bytes checking if the outermost closure is an array or object
func ParseBoolean ¶
ParseBoolean converts raw bytes to a bool value
func ParseInteger ¶
ParseInteger converts raw bytes to a int64 value
func ParseNumber ¶
ParseNumber converts raw bytes to a float64 value
func ParseString ¶
ParseString converts raw bytes to a string value
Types ¶
type Array ¶
type Array []Value
Array is an ordered list of Values
type Boolean ¶
type Boolean bool
Boolean represents true/false values
type Integer ¶
type Integer int
Integer represents a whole number
type Null ¶
type Null bool
Null represents explicit null values
func (Null) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface for Null
type Number ¶
type Number float64
Number represents a floating point number
func (Number) Integer ¶
Integer of Number will always panic TODO - should we allow this? rounding is nice. maybe.
type Object ¶
Object represents an object value
type ObjectValue ¶
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
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 ¶
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 ¶
TypeFromString takes a string & tries to return it's type defaulting to unknown if the type is unrecognized
func (Type) MarshalJSON ¶
MarshalJSON implements json.Marshaler on Type
func (*Type) UnmarshalJSON ¶
UnmarshalJSON implements json.Unmarshaler on Type
func (Type) ValueToBytes ¶
ValueToBytes takes already-parsed values & converts them to a slice of bytes
func (Type) ValueToString ¶
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 ¶
ConvertDecoded converts an interface that has been decoded into standard go types to a Value
func NewObjectValue ¶
NewObjectValue allocates a new Object Value
func UnmarshalJSON ¶
UnmarshalJSON turns a slice of JSON bytes into a Value
type ValueError ¶
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.