-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcmpp_header.py
More file actions
51 lines (30 loc) · 1.06 KB
/
cmpp_header.py
File metadata and controls
51 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'''
@所有请求的消息头
@totalLength 消息长度
@commandid 消息ID
@sequence 流水号,顺序累加,一对请求回应,流水号相同
'''
class cmppHeader(object):
def __init__(self, recvMessage):
self.setTotalLength(struct.upack('!I', recvMessage[0:4]))
self.setCommanId(struct.upack('!I', recvMessage[4:8]))
self.setSequence_id(struct.upack('!I', recvMessage[8:12]))
#
def getTotalLength(self):
return self.total_length
def setTotalLength(self, total_length):
self.total_length = total_length
def getCommandId(self):
return self.command_id
def setCommanId(self, command_id):
self.command_id = command_id
def setSequence_id(self, sequence_id):
self.sequence_id = sequence_id
def toStringBuffer(self, msg):
pass
# 字节流的形式写入buffer
def writeToByteBufferr(self):
return struct.pack("!III", self.total_length, self.command_id, self.sequence_id)
# 读取字节流中的int类型
def readToByteBufferr(self, resp_msg):
self.total_length,self.command_id,self.sequence_id=struct.upack('!III', resp_msg)