class StreamCommand(Structure): start = Magic("!") type = Magic(MSGID_STREAM_CMD) stream_type = ULInt8() update_rate_hz = ProtocolUInt8() checksum = CRCField(ProtocolChecksum(), checksum, 0, -4) termination = Magic("\r\n")
class BoxedGreedy(Structure): sof = Magic(b'\xAA') a = LengthField(UBInt8()) b = UBInt8() payload = Payload() c = UBInt16() d = VariableRawPayload(a) eof = Magic(b'\xbb')
class PortTrafficStatistics(Structure): port = UBInt8() bytes_received = UBInt64() bytes_sent = UBInt64() unknown_0 = Magic('\x00\x00\x00\x00\x00\x00\x00\x00') unknown_1 = Magic('\x00\x00\x00\x00\x00\x00\x00\x00') unknown_2 = Magic('\x00\x00\x00\x00\x00\x00\x00\x00') crc_error_packets = UBInt64()
class YPRUpdate(Structure): start = Magic("!") type = Magic("y") yaw = ProtocolFloat() pitch = ProtocolFloat() roll = ProtocolFloat() compass_heading = ProtocolFloat() checksum = CRCField(ProtocolChecksum(), checksum, 0, -4) termination = Magic("\r\n")
class MyDynamicLengthDispatchMessage(Structure): type = DispatchField(UBInt8()) body = DispatchTarget(None, type, { 0x1F: MySimpleFixedPayload, 0xCC: MyPayloadMessage, }) eof = Magic(b'EOF')
class QuaternionUpdate(Structure): start = Magic("!") type = Magic("q") q1 = ProtocolUInt16() q2 = ProtocolUInt16() q3 = ProtocolUInt16() q4 = ProtocolUInt16() accel_x = ProtocolSInt16() accel_y = ProtocolSInt16() accel_z = ProtocolSInt16() mag_x = ProtocolSInt16() mag_y = ProtocolSInt16() mag_z = ProtocolSInt16() temp_c = ProtocolFloat() checksum = CRCField(ProtocolChecksum(), checksum, 0, -4) termination = Magic("\r\n")
class StreamResponse(Structure): start = Magic("!") type = Magic("s") stream_type = ProtocolUInt8() gyro_fsr_dps = ProtocolUInt16() accel_fsr_g = ProtocolUInt16() update_rate_hz = ProtocolUInt16() yaw_offset_degrees = ProtocolFloat() q1_offset = ProtocolUInt16() q2_offset = ProtocolUInt16() q3_offset = ProtocolUInt16() q4_offset = ProtocolUInt16() flags = ProtocolUInt16() checksum = CRCField(ProtocolChecksum(), checksum, 0, -4) termination = Magic("\r\n")
class Frame(Structure): version = UBInt8() operation = UBInt8() result = UBInt16() reserved_0 = Magic('\x00\x00\x00\x00') _host_mac = UBInt8Sequence(6) host_mac = FieldProperty(_host_mac, onget=lambda v: unpack_mac(''.join(map(chr, v))), onset=lambda v: tuple(map(ord, pack_mac(v)))) _device_mac = UBInt8Sequence(6) device_mac = FieldProperty( _device_mac, onget=lambda v: unpack_mac(''.join(map(chr, v))), onset=lambda v: tuple(map(ord, pack_mac(v)))) reserved_1 = Magic('\x00\x00') sequence = UBInt16() signature = Magic('NSDP') reserved_2 = Magic('\x00\x00\x00\x00') messages = FieldArray(Message)
class EthernetFrame(Structure): preamble_sof = Magic('\xAA' * 8) # 8 bytes of 10101010 mac_dest = UBInt8Sequence(6) mac_source = UBInt8Sequence(6) ethertype = DispatchField(UBInt16()) payload = DispatchTarget(None, ethertype, { 0x0800: IPV4Frame, # 0x85DD: IPV6Message, # 0x0806: ARPMessage, }) checksum = UBInt32()
class DemoHeader(Structure): r"""1072 Byte header for .DEM file. This header has the following format: +-----------+---------------------------------------+ | Byte | Description | +===========+=======================================+ | 0-7 | Fixed string 'HL2DEMO\0'. | +-----------+---------------------------------------+ | 8-11 | Demo file protocol version. | +-----------+---------------------------------------+ | 12-15 | Network protocol version. | +-----------+---------------------------------------+ | 16-275 | Server name. | +-----------+---------------------------------------+ | 276-535 | Name of client who recorded the demo. | +-----------+---------------------------------------+ | 536-795 | Map name. | +-----------+---------------------------------------+ | 796-1055 | Game directory. | +-----------+---------------------------------------+ | 1056-1059 | Playback time in seconds. | +-----------+---------------------------------------+ | 1060-1063 | Number of ticks in demo. | +-----------+---------------------------------------+ | 1064-1067 | Number of frames in demo. | +-----------+---------------------------------------+ | 1068-1071 | Length of signon data. | +-----------+---------------------------------------+ """ header = Magic(b'HL2DEMO\x00') demo_protocol = ULInt32() network_protocol = ULInt32() server_name = FixedLengthString(consts.MAX_PATH) client_name = FixedLengthString(consts.MAX_PATH) map_name = FixedLengthString(consts.MAX_PATH) game_directory = FixedLengthString(consts.MAX_PATH) playback_time = SLFloat32() ticks = ULInt32() frames = ULInt32() signon_length = ULInt32()
def test_magic(self): magic_field = Magic('\xAA').create_instance(None) self.assertRaises(SuitcaseProgrammingError, magic_field.setval)
class CRCGreedyTail(Structure): payload = Payload() magic = Magic(b'~~') crc = CRCField(UBInt32(), crc32, 0, -1) # all (checksum zeroed)
class SuperMessage(Structure): magic = Magic(b'\xAA\xAA') # bitfield options = BitField(8, b1=BitBool(), b2=BitBool(), rest=BitNum(6)) # unsigned big endian ubint8 = UBInt8() ubint16 = UBInt16() ubint24 = UBInt24() ubint32 = UBInt32() ubint64 = UBInt64() # signed big endian sbint8 = SBInt8() sbint16 = SBInt16() sbint32 = SBInt32() sbint64 = SBInt64() # unsigned little endian ulint8 = ULInt8() ulint16 = ULInt16() ulint32 = ULInt32() ulint64 = ULInt64() # signed little endian slint8 = SLInt8() slint16 = SLInt16() slint32 = SLInt32() slint64 = SLInt64() # optional optional_one = ConditionalField(UBInt8(), lambda m: m.options.b1) optional_two = ConditionalField(UBInt8(), lambda m: m.options.b2) # sequences with variable lengths ubseql = LengthField(UBInt8()) ubseq = UBInt8Sequence(ubseql) sbseql = LengthField(UBInt8()) sbseq = SBInt8Sequence(sbseql) # sequences with fixed lengths ubseqf = UBInt8Sequence(5) sbseqf = SBInt8Sequence(5) # don't change anything... for test coverage ulint16_value = FieldProperty(ulint16) ulint16_byte_string = FieldProperty( ulint16, onget=lambda v: str(v), onset=lambda v: struct.unpack(">H", v)[0]) message_type = DispatchField(UBInt8()) submessage_length = LengthField(UBInt16()) submessage = DispatchTarget(submessage_length, message_type, {0xEF: SuperChild}) # checksum starts after beginning magic, ends before # the checksum crc = CRCField(UBInt16(), crc16_ccitt, 2, -3) eof = Magic(b'~')
class LongMagicSchema(Structure): magic = Magic(b'\xAA\xAA\xBB\xBB') value = SBInt64()
class MagicSchema(Structure): magic = Magic(b'\xAA\xAA') value = SBInt64()