MCPcopy
hub / github.com/davyxu/cellnet / DecodeMessage

Function DecodeMessage

codec/msgcodec.go:30–51  ·  view source on GitHub ↗

解码消息

(msgid int, data []byte)

Source from the content-addressed store, hash-verified

28
29// 解码消息
30func DecodeMessage(msgid int, data []byte) (interface{}, *cellnet.MessageMeta, error) {
31
32 // 获取消息元信息
33 meta := cellnet.MessageMetaByID(msgid)
34
35 // 消息没有注册
36 if meta == nil {
37 return nil, nil, cellnet.NewErrorContext("msg not exists", msgid)
38 }
39
40 // 创建消息
41 msg := meta.NewType()
42
43 // 从字节数组转换为消息
44 err := meta.Codec.Decode(data, msg)
45
46 if err != nil {
47 return nil, meta, err
48 }
49
50 return msg, meta, nil
51}
52
53func DecodeMessageByType(data []byte, msg interface{}) (*cellnet.MessageMeta, error) {
54

Callers 8

TestGogopbCodec_CodecFunction · 0.92
OnRecvMessageMethod · 0.92
RecvPacketFunction · 0.92
ResolveInboundEventFunction · 0.92
ResolveOutboundEventFunction · 0.92
RecvLTVPacketFunction · 0.92
ResoleveInboundEventFunction · 0.92
ResolveOutboundEventFunction · 0.92

Calls 4

MessageMetaByIDFunction · 0.92
NewErrorContextFunction · 0.92
NewTypeMethod · 0.80
DecodeMethod · 0.65

Tested by 1

TestGogopbCodec_CodecFunction · 0.74