Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import ctypes
- class Header_Decoder(ctypes.BigEndianStructure): # {
- _pack_ = 1
- _fields_ = [
- ('protocol_id', ctypes.c_uint8, 8), # 1 byte: byte 1, bits 00-07
- ('segmentation', ctypes.c_uint8, 3), # 3 bits: byte 2, bits 08-10
- ('transaction_type', ctypes.c_uint8, 5), # 5 bits: byte 2, bits 11-15
- ('packet_length', ctypes.c_uint32), # 4 bytes: bytes 3-6, bits 16-47
- ('checksum', ctypes.c_uint16), # 2 bytes: bytes 7-8, bits 48-63
- ]
- # } Header_Decoder
- HEADER_LENGHT_BYTES = ctypes.sizeof(Header_Decoder)
- packet = b'\xFF\x10\x00\x00\x00\x0C\x00\xE3\x48\x65\x79\x21'
- header = Header_Decoder.from_buffer_copy(packet[0 : 0 + HEADER_LENGHT_BYTES])
- print("Protocol ID:", header.protocol_id)
- print("Segmentation:", header.segmentation)
- print("Transaction type:", header.transaction_type)
- print("Checksum:", header.checksum)
- print("Data:", packet[HEADER_LENGHT_BYTES : header.packet_length].decode('ascii'))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement