예제 #1
0
class BoxedGreedy(Structure):
    sof = Magic(b'\xAA')
    a = LengthField(UBInt8())
    b = UBInt8()
    payload = Payload()
    c = UBInt16()
    d = VariableRawPayload(a)
    eof = Magic(b'\xbb')
예제 #2
0
class ConditionalDispatch(Structure):
    f1 = DispatchField(UBInt8())
    f2 = UBInt8()  # separate from f1
    length = LengthField(UBInt8())
    f3 = ConditionalField(DispatchTarget(length, f1, {
        0: EmptyStructure,
        1: BasicMessage
    }),
                          condition=lambda m: m.f2 == 255)
예제 #3
0
class MyBasicDispatchMessage(Structure):
    type = DispatchField(UBInt8())
    length = LengthField(UBInt16())
    body = DispatchTarget(
        length, type, {
            0x00: MyTargetMessage,
            0x01: MyOtherTargetMessage,
            None: MyDefaultTargetMessage
        })
예제 #4
0
class BGAPIFrame(Structure):
    head = LengthField(BitField(16,
                                is_event=BitBool(),
                                technology_type=BitNum(4),
                                length=BitNum(11)),
                       get_length=lambda f: f.length,
                       set_length=lambda f, l: setattr(f, 'length', l))
    class_id = UBInt8()
    command_id = UBInt8()
    payload = Payload(head)
예제 #5
0
class MyTargetMessage(Structure):
    # inherited from the parent message
    _length = LengthField(DependentField('length'))
    payload = VariableRawPayload(_length)
예제 #6
0
 class MyVarSeqMessage(Structure):
     type = UBInt8()
     length = LengthField(UBInt8())
     seq = UBInt8Sequence(length)
예제 #7
0
class SuperChild(Structure):
    options = DependentField('options')
    ubseq = DependentField('ubseq')
    length = LengthField(DependentField('submessage_length'))

    remaining = VariableRawPayload(length)
예제 #8
0
 class MyLengthyMessage(Structure):
     length = LengthField(UBInt16())
     payload = VariableRawPayload(length)
예제 #9
0
class ErrorCaseSchema(Structure):
    type = DispatchField(UBInt8())
    length = LengthField(UBInt8())
    body = DispatchTarget(length, type, {
        0x00: MagicSchema
    })
예제 #10
0
class ConditionalLength(Structure):
    f1 = UBInt8()
    f2 = ConditionalField(LengthField(UBInt8()), lambda m: m.f1 == 255)
    f3 = ConditionalField(Payload(length_provider=f2), lambda m: m.f1 == 255)
예제 #11
0
class PascalString16(Structure):
    length = LengthField(UBInt16())
    value = Payload(length)
예제 #12
0
class BasicMessageArrayNumElements(Structure):
    count = LengthField(UBInt8())
    array = FieldArray(BasicMessage, num_elements_provider=count)
예제 #13
0
class BasicMessageArrayAfter(Structure):
    count = LengthField(UBInt8(), multiplier=2)
    array = FieldArray(BasicMessage, count)
    after = UBInt8()
예제 #14
0
class UDPFrame(Structure):
    source_port = UBInt16()
    destination_port = UBInt16()
    length = LengthField(UBInt16())
    checksum = UBInt16()
    data = VariableRawPayload(length)
예제 #15
0
class MyOtherTargetMessage(Structure):
    #: Inherited from the parent message
    _length = LengthField(DependentField('length'))
    sequence = UBInt8Sequence(_length)
예제 #16
0
class MyDefaultTargetMessage(Structure):
    _length = LengthField(DependentField('length'))
    sequence = UBInt8Sequence(_length)
예제 #17
0
class ConditionalArrayGreedyAfter(Structure):
    length = LengthField(UBInt8())
    array = FieldArray(ConditionalArrayElement, length)
    greedy = Payload()
예제 #18
0
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'~')
예제 #19
0
 class MyMuiltipliedLengthMessage(Structure):
     length = LengthField(UBInt8(), multiplier=8)
     payload = VariableRawPayload(length)
예제 #20
0
class EchoProtocolFrame(Structure):
    frame_type = UBInt8()
    payload_length = LengthField(UBInt16())
    payload = Payload(payload_length)
예제 #21
0
class Message(Structure):
    tag = DispatchField(UBInt16())
    length = LengthField(UBInt16())
    message = DispatchTarget(length, tag, MESSAGE_DISPATCH_MAPPING)