codec

package
v0.0.0-...-3c4aecd Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2021 License: MulanPSL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthProtoWarpper        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowProtoWarpper          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupProtoWarpper = fmt.Errorf("proto: unexpected end of group")
)

Functions

func Register

func Register(fmt Type, codec Serializer)

Register 注册协议

Types

type Error

type Error struct {
	Code int
	Msg  string
}

错误消息格式

type IWrapper

type IWrapper interface {
	GetType() string
	GetData() []byte
}

IWrapper 消息外包装

type JSBuffer

type JSBuffer []byte

JSBuffer JavaScript的Buffer类型

func (*JSBuffer) ExtensionType

func (c *JSBuffer) ExtensionType() int8

func (*JSBuffer) Len

func (c *JSBuffer) Len() int

func (*JSBuffer) MarshalBinaryTo

func (c *JSBuffer) MarshalBinaryTo(b []byte) error

MarshalMsgpack 序列化JSBuffer

func (*JSBuffer) UnmarshalBinary

func (c *JSBuffer) UnmarshalBinary(b []byte) error

UnmarshalMsgpack 反序列化JSBuffer

type JSONWrapper

type JSONWrapper struct {
	Type string      `json:"type"`
	Data interface{} `json:"data,omitempty"`

	Code *int    `json:"code,omitempty"`
	Msg  *string `json:"msg,omitempty"`
}

JSONWrapper 消息外包装

type MessagePackJSWrapper

type MessagePackJSWrapper struct {
	Type string
	Data JSBuffer
}

MessagePackJSWrapper 消息外包装

func (MessagePackJSWrapper) GetData

func (w MessagePackJSWrapper) GetData() []byte

GetData _

func (MessagePackJSWrapper) GetType

func (w MessagePackJSWrapper) GetType() string

GetType _

type MessagePackWrapper

type MessagePackWrapper struct {
	Type string
	Data JSBuffer `msg:",extension"`
}

MessagePackWrapper 消息外包装

func (*MessagePackWrapper) DecodeMsg

func (z *MessagePackWrapper) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (MessagePackWrapper) EncodeMsg

func (z MessagePackWrapper) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (MessagePackWrapper) GetData

func (w MessagePackWrapper) GetData() []byte

GetData _

func (MessagePackWrapper) GetType

func (w MessagePackWrapper) GetType() string

GetType _

func (MessagePackWrapper) MarshalMsg

func (z MessagePackWrapper) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (MessagePackWrapper) Msgsize

func (z MessagePackWrapper) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (*MessagePackWrapper) UnmarshalMsg

func (z *MessagePackWrapper) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

type Ping

type Ping struct {
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

心跳检测,收到时回 Pong

func (*Ping) Descriptor

func (*Ping) Descriptor() ([]byte, []int)

func (*Ping) Marshal

func (m *Ping) Marshal() (dAtA []byte, err error)

func (*Ping) MarshalTo

func (m *Ping) MarshalTo(dAtA []byte) (int, error)

func (*Ping) MarshalToSizedBuffer

func (m *Ping) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Ping) ProtoMessage

func (*Ping) ProtoMessage()

func (*Ping) Reset

func (m *Ping) Reset()

func (*Ping) Size

func (m *Ping) Size() (n int)

func (*Ping) String

func (m *Ping) String() string

func (*Ping) Unmarshal

func (m *Ping) Unmarshal(dAtA []byte) error

func (*Ping) XXX_DiscardUnknown

func (m *Ping) XXX_DiscardUnknown()

func (*Ping) XXX_Marshal

func (m *Ping) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Ping) XXX_Merge

func (m *Ping) XXX_Merge(src proto.Message)

func (*Ping) XXX_Size

func (m *Ping) XXX_Size() int

func (*Ping) XXX_Unmarshal

func (m *Ping) XXX_Unmarshal(b []byte) error

type Pong

type Pong struct {
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

心跳检测,收到 Ping 时发送

func (*Pong) Descriptor

func (*Pong) Descriptor() ([]byte, []int)

func (*Pong) Marshal

func (m *Pong) Marshal() (dAtA []byte, err error)

func (*Pong) MarshalTo

func (m *Pong) MarshalTo(dAtA []byte) (int, error)

func (*Pong) MarshalToSizedBuffer

func (m *Pong) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*Pong) ProtoMessage

func (*Pong) ProtoMessage()

func (*Pong) Reset

func (m *Pong) Reset()

func (*Pong) Size

func (m *Pong) Size() (n int)

func (*Pong) String

func (m *Pong) String() string

func (*Pong) Unmarshal

func (m *Pong) Unmarshal(dAtA []byte) error

func (*Pong) XXX_DiscardUnknown

func (m *Pong) XXX_DiscardUnknown()

func (*Pong) XXX_Marshal

func (m *Pong) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*Pong) XXX_Merge

func (m *Pong) XXX_Merge(src proto.Message)

func (*Pong) XXX_Size

func (m *Pong) XXX_Size() int

func (*Pong) XXX_Unmarshal

func (m *Pong) XXX_Unmarshal(b []byte) error

type ProtoWarpper

type ProtoWarpper struct {
	// 消息名
	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	// 消息正文数据
	Data                 []byte   `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"`
	XXX_NoUnkeyedLiteral struct{} `json:"-"`
	XXX_unrecognized     []byte   `json:"-"`
	XXX_sizecache        int32    `json:"-"`
}

消息统一外包装

func (*ProtoWarpper) Descriptor

func (*ProtoWarpper) Descriptor() ([]byte, []int)

func (*ProtoWarpper) Marshal

func (m *ProtoWarpper) Marshal() (dAtA []byte, err error)

func (*ProtoWarpper) MarshalTo

func (m *ProtoWarpper) MarshalTo(dAtA []byte) (int, error)

func (*ProtoWarpper) MarshalToSizedBuffer

func (m *ProtoWarpper) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*ProtoWarpper) ProtoMessage

func (*ProtoWarpper) ProtoMessage()

func (*ProtoWarpper) Reset

func (m *ProtoWarpper) Reset()

func (*ProtoWarpper) Size

func (m *ProtoWarpper) Size() (n int)

func (*ProtoWarpper) String

func (m *ProtoWarpper) String() string

func (*ProtoWarpper) Unmarshal

func (m *ProtoWarpper) Unmarshal(dAtA []byte) error

func (*ProtoWarpper) XXX_DiscardUnknown

func (m *ProtoWarpper) XXX_DiscardUnknown()

func (*ProtoWarpper) XXX_Marshal

func (m *ProtoWarpper) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*ProtoWarpper) XXX_Merge

func (m *ProtoWarpper) XXX_Merge(src proto.Message)

func (*ProtoWarpper) XXX_Size

func (m *ProtoWarpper) XXX_Size() int

func (*ProtoWarpper) XXX_Unmarshal

func (m *ProtoWarpper) XXX_Unmarshal(b []byte) error

type SerialJSON

type SerialJSON struct{}

SerialJSON 序列化JSON

func (SerialJSON) Marshal

func (c SerialJSON) Marshal(val interface{}) []byte

Marshal 序列化

func (SerialJSON) MarshalBody

func (c SerialJSON) MarshalBody(val interface{}) []byte

func (SerialJSON) Unmarshal

func (c SerialJSON) Unmarshal(data []byte, val interface{}) error

Unmarshal 反序列化

func (SerialJSON) Unpack

func (c SerialJSON) Unpack(_ Type, data []byte) (string, []byte)

Unpack 解开包装

type SerialMessagePack

type SerialMessagePack struct{}

SerialMessagePack 序列化MessagePack

func (*SerialMessagePack) DecodeMsg

func (z *SerialMessagePack) DecodeMsg(dc *msgp.Reader) (err error)

DecodeMsg implements msgp.Decodable

func (SerialMessagePack) EncodeMsg

func (z SerialMessagePack) EncodeMsg(en *msgp.Writer) (err error)

EncodeMsg implements msgp.Encodable

func (SerialMessagePack) Marshal

func (c SerialMessagePack) Marshal(val interface{}) []byte

Marshal 序列化

func (SerialMessagePack) MarshalBody

func (c SerialMessagePack) MarshalBody(val interface{}) []byte

func (SerialMessagePack) MarshalMsg

func (z SerialMessagePack) MarshalMsg(b []byte) (o []byte, err error)

MarshalMsg implements msgp.Marshaler

func (SerialMessagePack) Msgsize

func (z SerialMessagePack) Msgsize() (s int)

Msgsize returns an upper bound estimate of the number of bytes occupied by the serialized message

func (SerialMessagePack) Unmarshal

func (c SerialMessagePack) Unmarshal(data []byte, val interface{}) error

Unmarshal 反序列化

func (*SerialMessagePack) UnmarshalMsg

func (z *SerialMessagePack) UnmarshalMsg(bts []byte) (o []byte, err error)

UnmarshalMsg implements msgp.Unmarshaler

func (SerialMessagePack) Unpack

func (c SerialMessagePack) Unpack(format Type, data []byte) (string, []byte)

Unpack 解开包装

type SerialProtobuf

type SerialProtobuf struct{}

SerialProtobuf 序列化protobuf

func (SerialProtobuf) Marshal

func (c SerialProtobuf) Marshal(msg interface{}) []byte

Marshal 序列化

func (SerialProtobuf) MarshalBody

func (c SerialProtobuf) MarshalBody(val interface{}) []byte

func (SerialProtobuf) Unmarshal

func (c SerialProtobuf) Unmarshal(data []byte, val interface{}) error

Unmarshal 反序列化

func (SerialProtobuf) Unpack

func (c SerialProtobuf) Unpack(format Type, data []byte) (string, []byte)

Unpack 解开包装

type Serializer

type Serializer interface {
	Marshal(msg interface{}) []byte
	MarshalBody(msg interface{}) []byte
	Unmarshal(data []byte, msg interface{}) error
	Unpack(fmt Type, data []byte) (string, []byte)
}

Serializer 序列化接口

func Get

func Get(fmt Type) Serializer

GetFormat 获取序列化格式

type Type

type Type string
const (
	JSON             Type = "json"
	MessagePack      Type = "msgpack"
	MessagePackExtJS Type = "msgpack#js"
	Protobuf         Type = "proto"
)

Jump to

Keyboard shortcuts

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