chg: [server] unpack header

pull/23/head
Terrtia 2018-12-05 17:05:46 +01:00
parent f25192cb64
commit 5431f085d0
No known key found for this signature in database
GPG Key ID: 1E1B1F50D84613D0
1 changed files with 28 additions and 1 deletions

View File

@ -8,6 +8,8 @@ from twisted.python.modules import getModule
from twisted.internet.protocol import Protocol
from ctypes import *
class Echo(Protocol):
#def __init__(self, factory):
@ -15,7 +17,32 @@ class Echo(Protocol):
def dataReceived(self, data):
print(data)
self.transport.write(data)
d = unpack(D4Header, data)
print('-----')
print(d.version)
print(d.type)
print('{}-{}'.format(d.uuid1, d.uuid2))
print(d.timestamp)
print('{}-{}-{}-{}'.format(d.hmac1, d.hmac2, d.hmac3, d.hmac4))
print(d.size)
class D4Header(Structure):
_fields_ = [
("version", c_uint8),
("type", c_uint8),
("uuid1", c_uint64),
("uuid2", c_uint64),
("timestamp", c_uint64),
("hmac1", c_uint64),
("hmac2", c_uint64),
("hmac3", c_uint64),
("hmac4", c_uint64),
("size", c_uint32),
]
def unpack(ctype, buffer):
c_str = create_string_buffer(buffer)
return cast(pointer(c_str), POINTER(ctype)).contents
def main(reactor):
log.startLogging(sys.stdout)