MCPcopy
hub / github.com/aceld/zinx / Pack

Method Pack

zpack/datapack_tlv_bigendian.go:31–52  ·  view source on GitHub ↗

Pack packs the message (compresses the data) (封包方法,压缩数据)

(msg ziface.IMessage)

Source from the content-addressed store, hash-verified

29// Pack packs the message (compresses the data)
30// (封包方法,压缩数据)
31func (dp *DataPack) Pack(msg ziface.IMessage) ([]byte, error) {
32 // Create a buffer to store the bytes
33 // (创建一个存放bytes字节的缓冲)
34 dataBuff := bytes.NewBuffer([]byte{})
35
36 // Write the message ID
37 if err := binary.Write(dataBuff, binary.BigEndian, msg.GetMsgID()); err != nil {
38 return nil, err
39 }
40
41 // Write the data length
42 if err := binary.Write(dataBuff, binary.BigEndian, msg.GetDataLen()); err != nil {
43 return nil, err
44 }
45
46 // Write the data
47 if err := binary.Write(dataBuff, binary.BigEndian, msg.GetData()); err != nil {
48 return nil, err
49 }
50
51 return dataBuff.Bytes(), nil
52}
53
54// Unpack unpacks the message (decompresses the data)
55// (拆包方法,解压数据)

Callers 15

ClinetFunction · 0.95
ClientJoinFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95
mainFunction · 0.95

Calls 4

WriteMethod · 0.80
GetMsgIDMethod · 0.65
GetDataLenMethod · 0.65
GetDataMethod · 0.65

Tested by 2

ClinetFunction · 0.76
ClientJoinFunction · 0.76