mirror of https://github.com/D4-project/d4-core
chg: [server] unpack header
parent
f25192cb64
commit
5431f085d0
|
@ -8,6 +8,8 @@ from twisted.python.modules import getModule
|
||||||
|
|
||||||
from twisted.internet.protocol import Protocol
|
from twisted.internet.protocol import Protocol
|
||||||
|
|
||||||
|
from ctypes import *
|
||||||
|
|
||||||
class Echo(Protocol):
|
class Echo(Protocol):
|
||||||
|
|
||||||
#def __init__(self, factory):
|
#def __init__(self, factory):
|
||||||
|
@ -15,7 +17,32 @@ class Echo(Protocol):
|
||||||
|
|
||||||
def dataReceived(self, data):
|
def dataReceived(self, data):
|
||||||
print(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):
|
def main(reactor):
|
||||||
log.startLogging(sys.stdout)
|
log.startLogging(sys.stdout)
|
||||||
|
|
Loading…
Reference in New Issue