msgpack

package module
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2021 License: Apache-2.0 Imports: 10 Imported by: 2

README

MessagePack for Golang

pipeline status coverage report Go Report Card

Installation

go get -u gitlab.com/komex/msgpack

License

This library is under the Apache License 2.0 License.

Documentation

Overview

Package msgpack implements functions for the encoding and decoding values in msgpack format.

Package msgpack implements functions for the encoding and decoding values in msgpack format.

Package msgpack implements functions for the encoding and decoding values in msgpack format.

Package msgpack implements functions for the encoding and decoding values in msgpack format.

Package msgpack implements functions for the encoding and decoding values in msgpack format.

Package msgpack implements functions for the encoding and decoding values in msgpack format.

Package msgpack implements functions for the encoding and decoding values in msgpack format.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNanosecondsTooLarge = errors.New("nanoseconds too large")
	ErrNegativeLength      = errors.New("length cannot be negative")
	ErrLengthTooLong       = errors.New("struct length is too long")
	ErrOverflow            = errors.New("value overflows int range")
	ErrUnexpectedFormat    = errors.New("unexpected format")
	ErrUnsupportedMapKey   = errors.New("decoded map key is unsupported")
	ErrUnsupportedType     = errors.New("value has unsupported type")
)

Package level errors.

Functions

func IsArray added in v1.1.0

func IsArray(format Format) bool

IsArray checks if format is an array.

func IsBin added in v1.1.0

func IsBin(format Format) bool

IsBin checks if format is from binary family.

func IsExt added in v1.1.0

func IsExt(format Format) bool

IsExt checks if format is from extension family.

func IsFixedArray added in v1.1.0

func IsFixedArray(format Format) bool

IsFixedArray checks if format is a fixed length array.

func IsFixedExt added in v1.1.0

func IsFixedExt(format Format) bool

IsFixedExt checks if format is a fixed length extension.

func IsFixedMap added in v1.1.0

func IsFixedMap(format Format) bool

IsFixedMap checks if format is a fixed length map.

func IsFixedNum added in v1.1.0

func IsFixedNum(format Format) bool

IsFixedNum checks if format is a fixed number value.

func IsFixedString added in v1.1.0

func IsFixedString(format Format) bool

IsFixedString checks if format is a fixed length string.

func IsFloat added in v1.2.0

func IsFloat(format Format) bool

IsFloat checks if format represents any float.

func IsInteger added in v1.2.0

func IsInteger(format Format) bool

IsInteger checks if format represents any integer.

func IsMap added in v1.1.0

func IsMap(format Format) bool

IsMap checks if format is a map.

func IsNegativeInteger added in v1.2.0

func IsNegativeInteger(format Format) bool

IsNegativeInteger checks if format represents negative integer.

func IsPositiveInteger added in v1.2.0

func IsPositiveInteger(format Format) bool

IsPositiveInteger checks if format represents positive integer.

func IsString added in v1.1.0

func IsString(format Format) bool

IsString checks if format is from string family.

Types

type CustomDecoder

type CustomDecoder interface {
	DecodeMsgpack(*Decoder) error
}

CustomDecoder declares method which indicates structure is support custom decoding from msgpack.

type CustomDecoderFunc added in v1.3.0

type CustomDecoderFunc func(*Decoder) error

CustomDecoderFunc defines a function implemented CustomDecoder interface.

func (CustomDecoderFunc) DecodeMsgpack added in v1.3.0

func (fn CustomDecoderFunc) DecodeMsgpack(dec *Decoder) error

DecodeMsgpack implements CustomDecoder interface.

type CustomEncoder

type CustomEncoder interface {
	EncodeMsgpack(*Encoder) error
}

CustomEncoder declares method which indicates structure is support custom encoding from msgpack.

type CustomEncoderFunc added in v1.3.0

type CustomEncoderFunc func(*Encoder) error

CustomEncoderFunc defines a function implemented CustomEncoder interface.

func (CustomEncoderFunc) EncodeMsgpack added in v1.3.0

func (fn CustomEncoderFunc) EncodeMsgpack(enc *Encoder) error

EncodeMsgpack implements CustomEncoder interface.

type Decoder

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

Decoder allows to decode msgpack stream from Reader.

func NewDecoder

func NewDecoder(r Reader) *Decoder

NewDecoder returns a new instance of msgpack Decoder.

func (*Decoder) ArrayLen

func (d *Decoder) ArrayLen() (int, error)

ArrayLen decodes size of msgpack array.

func (*Decoder) Bool

func (d *Decoder) Bool() (bool, error)

Bool decodes msgpack boolean value.

func (*Decoder) Bytes

func (d *Decoder) Bytes() ([]byte, error)

Bytes decodes msgpack string or bin as a bytes slice.

func (*Decoder) Ext added in v1.4.0

func (d *Decoder) Ext() (interface{}, error)

Ext decodes extension with registered custom decoder.

func (*Decoder) ExtData

func (d *Decoder) ExtData() (Ext, []byte, error)

ExtData decodes msgpack extension code and its data.

func (*Decoder) Float32

func (d *Decoder) Float32() (float32, error)

Float32 decodes msgpack float as float32.

func (*Decoder) Float64

func (d *Decoder) Float64() (float64, error)

Float64 decodes msgpack float as float64.

func (*Decoder) Format

func (d *Decoder) Format() (Format, error)

Format returns current msgpack format code.

func (*Decoder) Int

func (d *Decoder) Int() (int, error)

Int decodes msgpack integer as int.

func (*Decoder) Int16

func (d *Decoder) Int16() (int16, error)

Int16 decodes msgpack integer as int16.

func (*Decoder) Int32

func (d *Decoder) Int32() (int32, error)

Int32 decodes msgpack integer as int32.

func (*Decoder) Int64

func (d *Decoder) Int64() (int64, error)

Int64 decodes msgpack integer as int64.

func (*Decoder) Int8

func (d *Decoder) Int8() (int8, error)

Int8 decodes msgpack integer as int8.

func (*Decoder) Interface added in v1.2.0

func (d *Decoder) Interface() (interface{}, error)

Interface decodes unknown type msgpack value.

func (*Decoder) MapLen

func (d *Decoder) MapLen() (int, error)

MapLen decodes size of msgpack map.

func (*Decoder) Nil

func (d *Decoder) Nil() error

Nil decodes msgpack nil.

func (*Decoder) PeekFormat

func (d *Decoder) PeekFormat() (Format, error)

PeekFormat returns current msgpack format code but next call Format will return the same format.

func (*Decoder) RegisterExtDecoder added in v1.4.0

func (d *Decoder) RegisterExtDecoder(code Ext, fn ExtDecoderFn)

RegisterExtDecoder registers a custom decoder for extensions with specified code.

func (*Decoder) Reset

func (d *Decoder) Reset(r Reader)

Reset resets data source.

func (*Decoder) Skip added in v1.1.0

func (d *Decoder) Skip() error

Skip skips current msgpack object.

func (*Decoder) String

func (d *Decoder) String() (string, error)

String decodes msgpack string or bin as a string.

func (*Decoder) Time

func (d *Decoder) Time() (time.Time, error)

Time decodes time from Timestamp extension.

func (*Decoder) Uint

func (d *Decoder) Uint() (uint, error)

Uint decodes msgpack integer as uint.

func (*Decoder) Uint16

func (d *Decoder) Uint16() (uint16, error)

Uint16 decodes msgpack integer as uint16.

func (*Decoder) Uint32

func (d *Decoder) Uint32() (uint32, error)

Uint32 decodes msgpack integer as uint32.

func (*Decoder) Uint64

func (d *Decoder) Uint64() (uint64, error)

Uint64 decodes msgpack integer as uint64.

func (*Decoder) Uint8

func (d *Decoder) Uint8() (uint8, error)

Uint8 decodes msgpack integer as uint8.

type Encoder

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

Encoder allows to encode and write msgpack values to Writer.

func NewEncoder

func NewEncoder(w Writer) *Encoder

NewEncoder returns a new instance of Encoder.

func (*Encoder) ArrayLen

func (e *Encoder) ArrayLen(length int) error

ArrayLen encodes array length as msgpack.

func (*Encoder) Bool

func (e *Encoder) Bool(v bool) error

Bool encodes v as msgpack value.

func (*Encoder) Bytes

func (e *Encoder) Bytes(v []byte) error

Bytes encodes v as msgpack bin data.

func (*Encoder) ExtData added in v1.3.1

func (e *Encoder) ExtData(code Ext, data []byte) error

ExtData encodes data with specified Ext code.

func (*Encoder) Float32

func (e *Encoder) Float32(v float32) error

Float32 encodes v as msgpack value.

func (*Encoder) Float64

func (e *Encoder) Float64(v float64) error

Float64 encodes v as msgpack value.

func (*Encoder) Int

func (e *Encoder) Int(v int) error

Int encodes int as msgpack integer.

func (*Encoder) Int16

func (e *Encoder) Int16(v int16) error

Int16 encodes int16 as msgpack integer.

func (*Encoder) Int32

func (e *Encoder) Int32(v int32) error

Int32 encodes int32 as msgpack integer.

func (*Encoder) Int64

func (e *Encoder) Int64(v int64) error

Int64 encodes int64 as msgpack integer.

func (*Encoder) Int8

func (e *Encoder) Int8(v int8) error

Int8 encodes int8 as msgpack integer.

func (*Encoder) Interface added in v1.2.0

func (e *Encoder) Interface(value interface{}) error

Interface encodes any scalar value or structure has implemented CustomEncoder as msgpack value.

func (*Encoder) MapLen

func (e *Encoder) MapLen(length int) error

MapLen encodes map length as msgpack.

func (*Encoder) Nil

func (e *Encoder) Nil() error

Nil encodes v as msgpack value.

func (*Encoder) Reset

func (e *Encoder) Reset(w Writer)

Reset resets data destination.

func (*Encoder) String

func (e *Encoder) String(v string) error

String encodes v as msgpack string.

func (*Encoder) Time

func (e *Encoder) Time(time time.Time) error

Time encoder time as msgpack value.

func (*Encoder) Uint

func (e *Encoder) Uint(v uint) error

Uint encodes uint as msgpack integer.

func (*Encoder) Uint16

func (e *Encoder) Uint16(v uint16) error

Uint16 encodes uint16 as msgpack integer.

func (*Encoder) Uint32

func (e *Encoder) Uint32(v uint32) error

Uint32 encodes uint32 as msgpack integer.

func (*Encoder) Uint64

func (e *Encoder) Uint64(v uint64) error

Uint64 encodes uint64 as msgpack integer.

func (*Encoder) Uint8

func (e *Encoder) Uint8(v uint8) error

Uint8 encodes uint8 as msgpack integer.

type Ext

type Ext int8

Ext represents codes of msgpack extension.

const (
	// ExtTimestamp is a code of Timestamp extension.
	ExtTimestamp Ext = -1
)

func (Ext) String

func (i Ext) String() string

type ExtDecoderFn added in v1.4.0

type ExtDecoderFn func([]byte) (interface{}, error)

ExtDecoderFn defines an interface for custom extension decoders.

type Format

type Format uint8

Format represents format codes of msgpack types.

const (
	FormatPositiveFixIntMax Format = 0x7f // PositiveFixIntMax
	FormatNegativeFixIntMin Format = 0xe0 // NegativeFixIntMin

	FormatFixMapMin Format = 0x80 // FixMapMin
	FormatFixMapMax Format = 0x8f // FixMapMax

	FormatFixArrayMin Format = 0x90 // FixArrayMin
	FormatFixArrayMax Format = 0x9f // FixArrayMax

	FormatFixStringMin Format = 0xa0 // FixStringMin
	FormatFixStringMax Format = 0xbf // FixStringMax
)

Codes for range formats.

const (
	FormatNil Format = 0xc0 + iota // Nil

	FormatFalse // False
	FormatTrue  // True

	FormatBin8  // Bin8
	FormatBin16 // Bin16
	FormatBin32 // Bin32

	FormatExt8  // Ext8
	FormatExt16 // Ext16
	FormatExt32 // Ext32

	FormatFloat32 // Float32
	FormatFloat64 // Float64

	FormatUint8  // Uint8
	FormatUint16 // Uint16
	FormatUint32 // Uint32
	FormatUint64 // Uint64

	FormatInt8  // Int8
	FormatInt16 // Int16
	FormatInt32 // Int32
	FormatInt64 // Int64

	FormatFixExt1  // FixExt1
	FormatFixExt2  // FixExt2
	FormatFixExt4  // FixExt4
	FormatFixExt8  // FixExt8
	FormatFixExt16 // FixExt16

	FormatString8  // String8
	FormatString16 // String16
	FormatString32 // String32

	FormatArray16 // Array16
	FormatArray32 // Array32

	FormatMap16 // Map16
	FormatMap32 // Map32
)

Static format codes.

const (
	// FormatUnknown is default format code witch means a code is unknown.
	FormatUnknown Format = 0 // Unknown
)

func (Format) String

func (i Format) String() string

type FormatError added in v1.2.0

type FormatError struct {
	Format Format
	Err    error
}

FormatError is a wrapper for discard format errors.

func NewFormatError added in v1.2.0

func NewFormatError(format Format, err error) *FormatError

NewFormatError returns a new instance of FormatError.

func (FormatError) Cause added in v1.2.0

func (e FormatError) Cause() error

Cause returns origin error.

func (FormatError) Error added in v1.2.0

func (e FormatError) Error() string

Error implements error interface.

type Reader

type Reader interface {
	io.ByteScanner
	io.Reader
}

Reader describes interface required by Decoder.

type UnexpectedExtension

type UnexpectedExtension struct {
	Extension Ext
}

UnexpectedExtension is an error for unexpected extension while decoding.

func NewUnexpectedExtension

func NewUnexpectedExtension(extension Ext) *UnexpectedExtension

NewUnexpectedExtension creates a new instance of UnexpectedExtension.

func (UnexpectedExtension) Error

func (u UnexpectedExtension) Error() string

Error implements error interface.

type Writer

type Writer interface {
	io.ByteWriter
	io.Writer
}

Writer describes interface required by Encoder.

Jump to

Keyboard shortcuts

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