msgpack

package module
v0.0.0-...-93276f1 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2023 License: MIT Imports: 5 Imported by: 0

README

This library exposes a msgpack api that partially mimics c# System.Text.Json.JsonElement.

Go Reference

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewArrayElement

func NewArrayElement(values []Elementer) *arrayElement

NewArrayElement creates an array from the given values.

func NewBinElement

func NewBinElement(value []byte) *binElement

NewBinElement creates a binary element from the given bytes.

func NewBoolElement

func NewBoolElement(value bool) *boolElement

NewBoolElement creates a bool element from the given value.

func NewExtElement

func NewExtElement(value []byte) *extElement

NewExtElement creates an extension element from the given value.

func NewFloatElement

func NewFloatElement(value float64) *floatElement

NewFloatElement creates a float element from the given value.

func NewIntElement

func NewIntElement(value int64) *intElement

NewIntElement creates an integer element from the given value.

func NewNilElement

func NewNilElement() *nilElement

NewNilElement creates a nil element.

func NewObjectElement

func NewObjectElement(values []Elementer) *objectElement

NewObjectElement creates an object from the given values.

func NewStringElement

func NewStringElement(value string) *stringElement

NewStringElement creates a string element from the given value.

func NewUintElement

func NewUintElement(value uint64) *uintElement

NewUintElement creates an unsigned integer element from the given value.

Types

type ArrayWrapper

type ArrayWrapper interface {
	// Size returns the size of the array.
	Size() int
	// Get returns the element at the index postion.
	Get(index int) Elementer
}

ArrayWrapper exposes methods to access the items of an array.

type ElementType

type ElementType uint8
const (
	// ElementTypeNil nil value
	ElementTypeNil ElementType = iota + 1
	// ElementTypeBool bool value
	ElementTypeBool
	// ElementTypeFloat float value
	ElementTypeFloat
	// ElementTypeInt int value
	ElementTypeInt
	// ElementTypeUint uint value
	ElementTypeUint
	// ElementTypeString string value
	ElementTypeString
	// ElementTypeObject object value
	ElementTypeObject
	// ElementTypeArray array value
	ElementTypeArray
	// ElementTypeBin binary value
	ElementTypeBin
	// ElementTypeExtension extension value
	ElementTypeExtension
)

func (ElementType) String

func (i ElementType) String() string

type Elementer

type Elementer interface {
	// Type returns the type of the underlying value
	Type() ElementType
	// GetBool returns the boolean value or an error if the
	// underlying value is not bool.
	GetBool() (bool, error)
	// GetFloat returns the float64 value or an error if the
	// underlying value is not float64.
	GetFloat() (float64, error)
	// GetInt returns the int64 value or an error if the
	// underlying value is not int64.
	GetInt() (int64, error)
	// GetUint returns the uint64 value or an error if the
	// underlying value is not uint64.
	GetUint() (uint64, error)
	// GetString returns the string value or an error if the
	// underlying value is not string.
	GetString() (string, error)
	// GetBytes returns the byte array value or an error if the
	// underlying value is not []byte.
	GetBytes() ([]byte, error)
	// GetExtensionRaw returns raw msgpack encoded value of
	// the underlying extension or an error if the
	// underlying value is not extension.
	GetExtensionRaw() ([]byte, error)
	// AsArray returns an array wrapper if the underlying
	// value is an array.
	AsArray() (ArrayWrapper, error)
	// AsObject returns an object wrapper if the underlying
	// value is an object.
	AsObject() (ObjectWrapper, error)
}

func Unmarshal

func Unmarshal(data []byte) (Elementer, error)

Unmarshal decodes the MessagePack-encoded data and returns an interface Elementer.

func UnmarshalFromDecoder

func UnmarshalFromDecoder(dec *msgpack.Decoder) (Elementer, error)

UnmarshalFromDecoder consumes the decoder and returns an interface Elementer.

type ObjectWrapper

type ObjectWrapper interface {
	// Size returns the number of key of the object.
	Size() int
	// Get returns the key and value element at the index position.
	Get(index int) (Elementer, Elementer)
}

ObjectWrapper exposes methods to access the items of an object.

type TypeError

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

func (*TypeError) Error

func (t *TypeError) Error() string

Error implements error

Jump to

Keyboard shortcuts

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