DxMsgPack

package
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: May 14, 2020 License: MIT Imports: 13 Imported by: 0

README

DxMsgPack

Go版本的MsgPack协议包格式的解码和编码库
本库,目前实现了Go开发者习惯的标准版本的Marshal函数和Unmarshal函数来保证 和常规使用方式一致,另外也提供了可以自己解码格式的事件

Documentation

Index

Constants

View Source
const (
	Max_fixmap_len = 15
	Max_map16_len  = 1<<16 - 1
	Max_map32_len  = 1<<32 - 1

	Max_fixstr_len = 32 - 1
	Max_str8_len   = 1<<8 - 1
	Max_str16_len  = 1<<16 - 1
	Max_str32_len  = 1<<32 - 1
)

Variables

View Source
var (
	ErrInvalidateMsgPack = errors.New("Invalidate MsgPack Format")
	ErrInvalidateMap     = errors.New("Invalidate Map Format")
	ErrInvalidateMapKey  = errors.New("Invalidate Map Key,Key Can Only Int or String")
	ErrInvalidateArrLen  = errors.New("Is not a Array Len Flag")
)
View Source
var (
	ErrFiledNotSetable = errors.New("The Field not Setable")
	ErrStructKey       = errors.New("Struct Can only use String Key")
)
View Source
var (
	ErrUnSetOnStartArray = errors.New("Customer Decode has no ArrayEvent ")
	ErrCannotSet         = errors.New("Value can't set")
)

Functions

func FreeDecoder added in v1.1.2

func FreeDecoder(coder *MsgPackDecoder)

func FreeEncoder added in v1.1.2

func FreeEncoder(coder *MsgPackEncoder)

func Marshal

func Marshal(v ...interface{}) ([]byte, error)

func Unmarshal

func Unmarshal(data []byte, v ...interface{}) error

Types

type MsgPackCode

type MsgPackCode uint8
const (
	CodeUnkonw      MsgPackCode = 0
	PosFixedNumHigh MsgPackCode = 0x7f //0-7f的正数最大编码
	NegFixedNumLow  MsgPackCode = 0xe0 //固定大小的负数编码

	CodeNil MsgPackCode = 0xc0

	CodeFalse MsgPackCode = 0xc2
	CodeTrue  MsgPackCode = 0xc3

	CodeFloat  MsgPackCode = 0xca
	CodeDouble MsgPackCode = 0xcb

	CodeUint8  MsgPackCode = 0xcc
	CodeUint16 MsgPackCode = 0xcd
	CodeUint32 MsgPackCode = 0xce
	CodeUint64 MsgPackCode = 0xcf

	CodeInt8  MsgPackCode = 0xd0
	CodeInt16 MsgPackCode = 0xd1
	CodeInt32 MsgPackCode = 0xd2
	CodeInt64 MsgPackCode = 0xd3

	CodeFixedStrLow  MsgPackCode = 0xa0
	CodeFixedStrHigh MsgPackCode = 0xbf
	FixedStrMask     MsgPackCode = 0x1f
	CodeStr8         MsgPackCode = 0xd9
	CodeStr16        MsgPackCode = 0xda
	CodeStr32        MsgPackCode = 0xdb

	CodeBin8  MsgPackCode = 0xc4
	CodeBin16 MsgPackCode = 0xc5
	CodeBin32 MsgPackCode = 0xc6

	CodeFixedArrayLow  MsgPackCode = 0x90
	CodeFixedArrayHigh MsgPackCode = 0x9f
	FixedArrayMask     MsgPackCode = 0xf
	CodeArray16        MsgPackCode = 0xdc
	CodeArray32        MsgPackCode = 0xdd

	CodeFixedMapLow  MsgPackCode = 0x80
	CodeFixedMapHigh MsgPackCode = 0x8f
	FixedMapMask     MsgPackCode = 0xf
	CodeMap16        MsgPackCode = 0xde
	CodeMap32        MsgPackCode = 0xdf

	CodeFixExt1  MsgPackCode = 0xd4
	CodeFixExt2  MsgPackCode = 0xd5
	CodeFixExt4  MsgPackCode = 0xd6
	CodeFixExt8  MsgPackCode = 0xd7 //64位时间格式
	CodeFixExt16 MsgPackCode = 0xd8
	CodeExt8     MsgPackCode = 0xc7 //96位时间格式
	CodeExt16    MsgPackCode = 0xc8
	CodeExt32    MsgPackCode = 0xc9
)

func (MsgPackCode) IsArray

func (code MsgPackCode) IsArray() bool

func (MsgPackCode) IsBin

func (code MsgPackCode) IsBin() bool

func (MsgPackCode) IsExt

func (code MsgPackCode) IsExt() bool

func (MsgPackCode) IsFixedNum

func (code MsgPackCode) IsFixedNum() bool

func (MsgPackCode) IsInt

func (code MsgPackCode) IsInt() bool

func (MsgPackCode) IsMap

func (code MsgPackCode) IsMap() bool

func (MsgPackCode) IsStr

func (code MsgPackCode) IsStr() bool

type MsgPackDecoder

type MsgPackDecoder struct {
	OnParserNormalValue func(v interface{})
	OnStartMap          func(mapLen int, keyIsStr bool) (mapInterface interface{}) //开始一个字符串键值Map,指定返回的Map结构对象
	OnParserStrMapKv    func(mapInterface interface{}, key string, v interface{})
	OnParserIntKeyMapKv func(mapInterface interface{}, intKey int64, v interface{})
	OnStartArray        func(arrLen int) (arrInterface interface{})                                       //开始数组时候触发
	OnStartStrMapArray  func(arrLen int, Key string, mapInterface interface{}) (arrInterface interface{}) //开始数组时候触发
	OnStartIntMapArray  func(arrLen int, Key int64, mapInterface interface{}) (arrInterface interface{})  //开始数组时候触发
	OnParserArrElement  func(arrInterface interface{}, index int, v interface{})                          //解析数组元素触发
	OnParserArrObject   func(arrInterface interface{}, index int) (object interface{})                    //数组中是复杂对象
	// contains filtered or unexported fields
}

func NewDecoder

func NewDecoder(r io.Reader) *MsgPackDecoder

func (*MsgPackDecoder) BinaryLen

func (coder *MsgPackDecoder) BinaryLen(code MsgPackCode) (int, error)

func (*MsgPackDecoder) Decode2Interface

func (coder *MsgPackDecoder) Decode2Interface() (interface{}, error)

func (*MsgPackDecoder) DecodeArray2StdSlice

func (coder *MsgPackDecoder) DecodeArray2StdSlice(code MsgPackCode, arr *[]interface{}) error

func (*MsgPackDecoder) DecodeArrayCustomer

func (coder *MsgPackDecoder) DecodeArrayCustomer(code MsgPackCode) error

func (*MsgPackDecoder) DecodeArrayElementCustom

func (coder *MsgPackDecoder) DecodeArrayElementCustom(arrinterface interface{}, index int) error

func (*MsgPackDecoder) DecodeArrayLen

func (coder *MsgPackDecoder) DecodeArrayLen(code MsgPackCode) (int, error)

func (*MsgPackDecoder) DecodeArrayStd

func (coder *MsgPackDecoder) DecodeArrayStd(code MsgPackCode) ([]interface{}, error)

func (*MsgPackDecoder) DecodeBinary

func (coder *MsgPackDecoder) DecodeBinary(code MsgPackCode) ([]byte, error)

func (*MsgPackDecoder) DecodeBool

func (coder *MsgPackDecoder) DecodeBool(code MsgPackCode) (bool, error)

func (*MsgPackDecoder) DecodeCustom

func (coder *MsgPackDecoder) DecodeCustom() error

func (*MsgPackDecoder) DecodeDateTime

func (coder *MsgPackDecoder) DecodeDateTime(code MsgPackCode) (DxCommonLib.TDateTime, error)

func (*MsgPackDecoder) DecodeDateTime_Go

func (coder *MsgPackDecoder) DecodeDateTime_Go(code MsgPackCode) (time.Time, error)

func (*MsgPackDecoder) DecodeExtValue

func (coder *MsgPackDecoder) DecodeExtValue(code MsgPackCode) ([]byte, error)

func (*MsgPackDecoder) DecodeFloat

func (coder *MsgPackDecoder) DecodeFloat(code MsgPackCode) (float64, error)

func (*MsgPackDecoder) DecodeInt

func (coder *MsgPackDecoder) DecodeInt(code MsgPackCode) (int64, error)

func (*MsgPackDecoder) DecodeMapLen

func (coder *MsgPackDecoder) DecodeMapLen(mapcode MsgPackCode) (int, error)

func (*MsgPackDecoder) DecodeStand

func (coder *MsgPackDecoder) DecodeStand(v interface{}) error

func (*MsgPackDecoder) DecodeString

func (coder *MsgPackDecoder) DecodeString(code MsgPackCode) ([]byte, error)

func (*MsgPackDecoder) DecodeUnknownMapCustom

func (coder *MsgPackDecoder) DecodeUnknownMapCustom(strcode MsgPackCode) error

func (*MsgPackDecoder) DecodeUnknownMapStd

func (coder *MsgPackDecoder) DecodeUnknownMapStd(strcode MsgPackCode) (interface{}, error)

func (*MsgPackDecoder) DecodeValue

func (coder *MsgPackDecoder) DecodeValue(v reflect.Value) error

func (*MsgPackDecoder) GetDecoderFunc

func (coder *MsgPackDecoder) GetDecoderFunc(typ reflect.Type) Coders.DecoderFunc

func (*MsgPackDecoder) Name

func (coder *MsgPackDecoder) Name() string

func (*MsgPackDecoder) ReSetReader

func (coder *MsgPackDecoder) ReSetReader(r io.Reader)

func (*MsgPackDecoder) Read

func (coder *MsgPackDecoder) Read(b []byte) error

func (*MsgPackDecoder) ReadBigEnd16

func (coder *MsgPackDecoder) ReadBigEnd16() (uint16, error)

func (*MsgPackDecoder) ReadBigEnd32

func (coder *MsgPackDecoder) ReadBigEnd32() (uint32, error)

func (*MsgPackDecoder) ReadBigEnd64

func (coder *MsgPackDecoder) ReadBigEnd64() (uint64, error)

func (*MsgPackDecoder) ReadCode

func (coder *MsgPackDecoder) ReadCode() (MsgPackCode, error)

func (*MsgPackDecoder) Skip

func (coder *MsgPackDecoder) Skip() error

func (*MsgPackDecoder) SkipByCode

func (coder *MsgPackDecoder) SkipByCode(code MsgPackCode) (err error)

func (*MsgPackDecoder) UnreadByte

func (coder *MsgPackDecoder) UnreadByte() error

type MsgPackEncoder

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

func NewEncoder

func NewEncoder(w io.Writer) *MsgPackEncoder

func (*MsgPackEncoder) Buffer

func (encoder *MsgPackEncoder) Buffer() []byte

func (*MsgPackEncoder) EncodeArrLen

func (encoder *MsgPackEncoder) EncodeArrLen(arrLen int) (int, error)

func (*MsgPackEncoder) EncodeBinary

func (encoder *MsgPackEncoder) EncodeBinary(bt []byte) (err error)

func (*MsgPackEncoder) EncodeBool

func (encoder *MsgPackEncoder) EncodeBool(v bool) (err error)

func (*MsgPackEncoder) EncodeCustom

func (coder *MsgPackEncoder) EncodeCustom() error

func (*MsgPackEncoder) EncodeDateTime

func (encoder *MsgPackEncoder) EncodeDateTime(dt DxCommonLib.TDateTime) (err error)

func (*MsgPackEncoder) EncodeDouble

func (encoder *MsgPackEncoder) EncodeDouble(v float64) (err error)

func (*MsgPackEncoder) EncodeFloat

func (encoder *MsgPackEncoder) EncodeFloat(v float32) (err error)

func (*MsgPackEncoder) EncodeInt

func (encoder *MsgPackEncoder) EncodeInt(vint int64) (err error)

func (*MsgPackEncoder) EncodeMapLen

func (encoder *MsgPackEncoder) EncodeMapLen(maplen int) (err error)

func (*MsgPackEncoder) EncodeStand

func (encoder *MsgPackEncoder) EncodeStand(v interface{}) error

func (*MsgPackEncoder) EncodeString

func (encoder *MsgPackEncoder) EncodeString(str string) (err error)

func (*MsgPackEncoder) EncodeTime

func (encoder *MsgPackEncoder) EncodeTime(t time.Time) (err error)

func (*MsgPackEncoder) GetEncoderFunc

func (coder *MsgPackEncoder) GetEncoderFunc(typ reflect.Type) Coders.EncoderFunc

func (*MsgPackEncoder) Name

func (encoder *MsgPackEncoder) Name() string

func (*MsgPackEncoder) ReSet

func (encoder *MsgPackEncoder) ReSet(w io.Writer)

func (*MsgPackEncoder) Write

func (encoder *MsgPackEncoder) Write(b []byte) error

func (*MsgPackEncoder) WriteByte

func (encoder *MsgPackEncoder) WriteByte(b byte) error

func (*MsgPackEncoder) WriteUint16

func (encoder *MsgPackEncoder) WriteUint16(u16 uint16, bytecode MsgPackCode) (err error)

func (*MsgPackEncoder) WriteUint32

func (encoder *MsgPackEncoder) WriteUint32(u32 uint32, bytecode MsgPackCode) (err error)

func (*MsgPackEncoder) WriteUint64

func (encoder *MsgPackEncoder) WriteUint64(u64 uint64, bytecode MsgPackCode) (err error)

Jump to

Keyboard shortcuts

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