Merge branch 'master' of github.com:D4-project/d4-core

pull/23/head
Gerard Wagener 2018-12-03 09:14:14 +01:00
commit 1c7b8174ba
1 changed files with 31 additions and 0 deletions

31
server/test_ctypes.py Executable file
View File

@ -0,0 +1,31 @@
#!/usr/bin/env python3
# -*-coding:UTF-8 -*
from ctypes import *
class D4Header(Structure):
_fields_ = [
("version", c_uint8),
("type", c_uint8),
#("uuid", c_uint128),
("uuid", c_uint64),
("timestamp", c_uint64),
#("hmac", c_uint256),
("hmac", c_uint64),
("size", c_uint32),
]
def pack(ctype_instance):
return string_at(byref(ctype_instance), sizeof(ctype_instance))
def unpack(ctype, buffer):
c_str = create_string_buffer(buffer)
return cast(pointer(c_str), POINTER(ctype)).contents
if __name__ == '__main__':
d4h = D4Header(1,1,88888,1543398024,233243445342,342)
print(d4h.version)
buffer = pack(d4h)
print(buffer)
d = unpack(D4Header, buffer)
assert(d4h.version == d.version)