value

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2020 License: Apache-2.0 Imports: 16 Imported by: 4

README

value

Value in GO

List
v := value.List()

v.Insert(value.Boolean(true))
v.Insert(value.Long(123))
v.Insert(value.Double(-12.34))
v.Insert(value.Utf8("text"))
v.Insert(value.Raw([]byte{0, 1, 2}, false))

mp, _ := value.Pack(v)

c, err := value.Unpack(mp, false)
if err != nil {
    t.Errorf("unpack fail %v", err)
}

require.True(t, v.Equal(c))
Map
b = value.Map()

c := value.Map()
c.Put("5", value.Long(5))

b.Put("name", value.Utf8("name"))
b.Put("123", value.Long(123))
b.Put("map", c)

Documentation

Index

Constants

View Source
const (
	InvalidKey keyType = iota
	INDEX
	KEY
)
View Source
const (
	InvalidOp opCode = iota
	PUT
	REMOVE
)

Variables

View Source
var Base64Prefix = "base64,"
View Source
var DecimalExpDelim = byte('x')
View Source
var DecimalExpDelimStr = "x"
View Source
var FirstIndex = 1
View Source
var InitTableSize = 16
View Source
var PrecisionLevel = 0.00001
View Source
var UnknownPrefix = "data:application/x-msgpack-ext;"

Functions

func Expression

func Expression(str string) *expression

func Hex

func Hex(val Value) string

func Json

func Json(val Value) string

func List

func List() *tableValue

func Map

func Map() *tableValue

func MessagePacker

func MessagePacker(w io.Writer) *messagePacker

func MessageParser

func MessageParser() *messageParser

func MessageReader

func MessageReader(r io.Reader) *messageIOUnpacker

func MessageUnpacker

func MessageUnpacker(buf []byte, copy bool) *messageBufUnpacker

func Pack

func Pack(val Value) ([]byte, error)

func ParseBoolean

func ParseBoolean(str string) boolValue

func ReadStream

func ReadStream(r io.Reader, out chan<- Value) error

func Unknown

func Unknown(tagAndData []byte) unknownValue

func UnpackBigInt

func UnpackBigInt(data []byte) (*big.Int, error)

func UnpackDecimal

func UnpackDecimal(data []byte) (decimal.Decimal, error)

func Write

func Write(w io.Writer, val Value) error

func WriteStream

func WriteStream(w io.Writer, valueC <-chan Value) error

Types

type Bool

type Bool interface {
	Value

	Boolean() bool
}

func Boolean

func Boolean(b bool) Bool

type Expr

type Expr interface {
	Empty() bool

	Size() int

	GetAt(int) string

	GetPath() []string

	String() string
}

type Ext

type Ext byte
const (
	UnknownExt Ext = iota

	BigIntExt
	DecimalExt

	MaxExt
)

type Extension

type Extension interface {
	Value

	Native() []byte
}

type Format

type Format int
const (
	EOF Format = iota
	UnexpectedEOF
	NilToken
	BoolToken
	LongToken
	DoubleToken
	FixExtToken
	BinHeader
	StrHeader
	ListHeader
	MapHeader
	ExtHeader
)

type Kind

type Kind int
const (
	INVALID Kind = iota
	BOOL
	NUMBER
	STRING
	TABLE
	UNKNOWN
)

type Number

type Number interface {
	Value

	Type() NumberType

	IsNaN() bool

	Long() int64

	Double() float64

	BigInt() *big.Int

	Decimal() decimal.Decimal

	Add(Number) Number

	Subtract(Number) Number
}

func BigInt

func BigInt(val *big.Int) Number

func Decimal

func Decimal(dec decimal.Decimal) Number

func Double

func Double(val float64) Number

func Long

func Long(val int64) Number

func Nan

func Nan() Number

func ParseNumber

func ParseNumber(str string) Number

type NumberType

type NumberType int
const (
	InvalidNumber NumberType = iota
	LONG
	DOUBLE
	BIGINT
	DECIMAL
)

func (NumberType) String

func (t NumberType) String() string

type Packer

type Packer interface {
	PackNil()

	PackBool(bool)

	PackLong(int64)

	PackDouble(float64)

	PackStr(string)

	PackBin([]byte)

	PackExt(xtag Ext, data []byte)

	PackList(int)

	PackMap(int)

	PackRaw([]byte)

	Error() error
}

type Parser

type Parser interface {
	ParseBool([]byte) bool

	ParseLong([]byte) int64

	ParseDouble([]byte) float64

	ParseBin([]byte) int

	ParseStr([]byte) int

	ParseList([]byte) int

	ParseMap([]byte) int

	ParseExt([]byte) (int, []byte)

	Error() error
}

type String

type String interface {
	Value

	Type() StringType

	Len() int

	Utf8() string

	Raw() []byte
}

func ParseString

func ParseString(str string) String

func Raw

func Raw(val []byte, copyFlag bool) String

func Utf8

func Utf8(val string) String

type StringType

type StringType int
const (
	InvalidString StringType = iota
	UTF8
	RAW
)

func (StringType) String

func (t StringType) String() string

type Table

type Table interface {
	Value

	Type() TableType

	Get(string) Value

	GetTable(string) Table

	GetBool(string) Bool

	GetNumber(string) Number

	GetString(string) String

	GetAt(int) Value

	GetTableAt(int) Table

	GetBoolAt(int) Bool

	GetNumberAt(int) Number

	GetStringAt(int) String

	GetExp(Expr) Value

	GetTableExp(Expr) Table

	GetBoolExp(Expr) Bool

	GetNumberExp(Expr) Number

	GetStringExp(Expr) String

	Insert(Value)

	Put(key string, value Value)

	PutAt(index int, value Value)

	PutExp(exp Expr, value Value)

	Remove(string)

	RemoveAt(int)

	RemoveExp(Expr)

	Map() map[string]Value

	List() []Value

	Keys() []string

	Indexes() []int

	MaxIndex() int

	Size() int

	Clear()

	Compact()

	Sort()

	Version() uint64

	SetVersion(uint64)
}

type TableType

type TableType int
const (
	InvalidTable TableType = iota
	LIST
	MAP
)

func (TableType) String

func (t TableType) String() string

type Unpacker

type Unpacker interface {
	Next() (Format, []byte)

	Read(int) ([]byte, error)
}

type Value

type Value interface {
	json.Marshaler
	encoding.BinaryMarshaler

	Kind() Kind

	Class() reflect.Type

	String() string

	Object() interface{}

	Pack(Packer)

	PrintJSON(out *strings.Builder)

	Equal(Value) bool
}

func Parse

func Parse(unpacker Unpacker, parser Parser) (Value, error)

func Read

func Read(r io.Reader) (Value, error)

func Unpack

func Unpack(buf []byte, copy bool) (Value, error)

type Writer

type Writer interface {
	WriteNil() []byte

	WriteBool(val bool) []byte

	WriteLong(val int64) []byte

	WriteDouble(val float64) []byte

	WriteBinHeader(len int) []byte

	WriteStrHeader(len int) []byte

	WriteExtHeader(len int, xtag byte) []byte

	WriteArrayHeader(len int) []byte

	WriteMapHeader(len int) []byte
}

Jump to

Keyboard shortcuts

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