Documentation
¶
Index ¶
Constants ¶
View Source
const ( ProtocolLength = 82 PackagerLength = 8 )
View Source
const (
MagicNumber = 0x80DFEC60
)
头信息
Variables ¶
View Source
var ( ProtocolJson = Protocol{'J', 'S', 'O', 'N', '\000', 'Y', 'A', 'R'} ProtocolMsgpack = Protocol{'M', 'S', 'G', 'P', 'A', 'C', 'K'} )
Functions ¶
This section is empty.
Types ¶
type EncoderJson ¶
type EncoderJson struct {
}
JSON处理器
func (*EncoderJson) ContentType ¶
func (p *EncoderJson) ContentType() string
func (*EncoderJson) ShowProtocol ¶ added in v0.1.14
func (p *EncoderJson) ShowProtocol() Protocol
type EncoderMsgpack ¶
type EncoderMsgpack struct {
}
msgpack处理器,兼容json tag定义
func (*EncoderMsgpack) ContentType ¶
func (p *EncoderMsgpack) ContentType() string
func (*EncoderMsgpack) Decode ¶
func (p *EncoderMsgpack) Decode(body []byte, response *Response) error
func (*EncoderMsgpack) ShowProtocol ¶ added in v0.1.14
func (p *EncoderMsgpack) ShowProtocol() Protocol
type Exception ¶
type Exception struct {
// contains filtered or unexported fields
}
供JSON解析及外部使用的异常结构体
func (*Exception) UnmarshalJSON ¶
type Header ¶
type Header struct {
Id uint32
Version uint16
MagicNumber uint32
Reserved uint32
Provider [28]byte
Encrypt uint32
Token [32]byte
BodyLength uint32
Packager Protocol
}
func NewHeaderWithBody ¶
type Pack ¶
type Pack interface {
Encode(*Request) ([]byte, error)
ContentType() string
Decode([]byte, *Response) error
ShowProtocol() Protocol
}
定义数据编码解码接口
type Request ¶
type Request struct {
Protocol Protocol `json:"-" msgpack:"-"`
Addr string `json:"-" msgpack:"-"`
Id uint32 `json:"i" msgpack:"i"`
Method string `json:"m" msgpack:"m"`
Params interface{} `json:"p" msgpack:"p"`
}
请求结构体
func NewRequest ¶
type Response ¶
type Response struct {
Protocol Protocol `json:"-" msgpack:"-"`
Id uint32 `json:"i" msgpack:"i"`
Except *Exception `json:"e" msgpack:"e"`
Out string `json:"o" msgpack:"o"`
Status StatusType `json:"s" msgpack:"s"`
Retval interface{} `json:"r" msgpack:"r"`
}
响应结构体
type StatusType ¶
type StatusType int
响应
const ( StatusOkey StatusType = 0x0 ErrPackager StatusType = 0x1 ErrProtocol StatusType = 0x2 ErrRequest StatusType = 0x4 ErrOutput StatusType = 0x8 ErrTransport StatusType = 0x10 ErrForbidden StatusType = 0x20 ErrException StatusType = 0x40 ErrEmptyResponse StatusType = 0x80 )
Click to show internal directories.
Click to hide internal directories.