forked from claudiacor/imcpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPacket.py
More file actions
46 lines (39 loc) · 1.11 KB
/
Packet.py
File metadata and controls
46 lines (39 loc) · 1.11 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
from Message import *
import Factory
def serialize(msg, bfr):
msg.serializeHeader(bfr)
msg.serializeFields(bfr)
total = msg.getSerializationSize()
return total
def deserialize(msg, bfr):
sync = struct.unpack_from('<H',bfr,offset = 0)
offset += struct.calcsize('<' + 'H')
if(hex(sync) == DUNE_IMC_CONST_SYNC):
vals = struct.unpack_from('<HHdHBHB',bfr, offset)
mgid = vals[0]
size = vals[1]
timestamp = vals[2]
src = vals[3]
src_ent = vals[4]
dst = vals[5]
dst_ent = vals[6]
elif(hex(sync) == DUNE_IMC_CONST_SYNC_REV):
vals = struct.unpack_from('>HHdHBHB',bfr, offset)
mgid = vals[0]
size = vals[1]
timestamp = vals[2]
src = vals[3]
src_ent = vals[4]
dst = vals[5]
dst_ent = vals[6]
msg = Factory.produce(mgid)
msg.deserializeFields(bfr)
msg.sync = sync
msg.mgid = mgid
msg.size = size
msg.timestamp = timestamp
msg.src = src
msg.src_ent = src_ent
msg.dst = dst
msg.dst_ent = dst_ent
return msg