Exemple #1
0
            class Struct(Structure):
                f1 = FixedLengthField(2)
                f2 = FixedLengthField(1, skip=0)
                f3 = FixedLengthField(3)

                class Meta:
                    alignment = a
Exemple #2
0
        class Struct(Structure):
            bit1 = BitField(length=1, realign=True)
            byte = FixedLengthField(length=1)
            bit2 = BitField(length=1)

            class Meta:
                alignment = 2
Exemple #3
0
    def test_obtain_value(self):
        class En(enum.Enum):
            TEST = b'b'

        field = EnumField(FixedLengthField(1), En)

        self.assertFieldToStreamEqual(b'b', En.TEST, field)
        self.assertFieldToStreamEqual(b'b', 'TEST', field)
        self.assertFieldToStreamEqual(b'b', b'b', field)
        with self.assertRaises(TypeError):
            self.assertFieldToStreamEqual(b'b', 'x', field)
Exemple #4
0
 def test_length(self):
     self.assertFieldStreamEqual(b"\x02\x01\x00\x01", [513, 1],
                                 ArrayField(IntegerField(2, 'big'),
                                            length=4,
                                            name='field'),
                                 parsed_fields={'field': None})
     self.assertFieldStreamEqual(b"\x02\x01\x00\x01", [b"\x02\x01\x00\x01"],
                                 ArrayField(FixedLengthField(-1),
                                            length=4,
                                            name='field'),
                                 parsed_fields={'field': None})
     self.assertFieldStreamEqual(b"\x02\x01\x00\x01",
                                 [b"\x02\x01", b"\x00\x01"],
                                 ArrayField(FixedLengthField(2),
                                            length=4,
                                            name='field'),
                                 parsed_fields={'field': None})
     self.assertFieldStreamEqual(b"\x02\x01\x00\x01",
                                 [b"\x02\x01", b"\x00\x01"],
                                 ArrayField(FixedLengthField(2),
                                            length=-1,
                                            name='field'),
                                 parsed_fields={'field': None})
Exemple #5
0
 def test_len(self):
     self.assertEqual(1, len(EnumField(FixedLengthField(1), enum.Enum)))
Exemple #6
0
 class SubStructure(Structure):
     length = IntegerField(1, signed=False)
     numbers = ArrayField(FixedLengthField(length=lambda s: s.length),
                          count='length')
Exemple #7
0
        class S(Structure):
            a = FixedLengthField(length=6)

            class Meta:
                capture_raw = True
Exemple #8
0
 class Struct1(Structure):
     byte1 = FixedLengthField(length=1)
Exemple #9
0
 class Inner(Structure):
     o = FixedLengthField(length=2)
     a = FixedLengthField(length=2)
Exemple #10
0
 class Struct(Structure):
     bit1 = BitField(length=1)
     bit2 = BitField(length=1)
     byte = FixedLengthField(length=1)
Exemple #11
0
 class TestStructure(Structure):
     field2 = FixedLengthField(length='length', lazy=True)
     field3 = FixedLengthField(length=1)
     length = IntegerField(offset=-1, length=1, lazy=True)
Exemple #12
0
 class TestStructure(Structure):
     field1 = FixedLengthField(length=1, lazy=True)
     field2 = IntegerField(offset=1, length=1, lazy=True)
Exemple #13
0
 class TestStructure(Structure):
     field1 = IntegerField(length=1, lazy=True)
     field2 = FixedLengthField(length='field1', lazy=True)
     field3 = FixedLengthField(length=1)
Exemple #14
0
 class TestStructure(Structure):
     field1 = FixedLengthField(length=3, lazy=True)
Exemple #15
0
 class TestStructure(Structure):
     field1 = TerminatedField(b'\0', lazy=True)
     field2 = FixedLengthField(length=3, lazy=True)
     field3 = TerminatedField(b'\0', lazy=True)
Exemple #16
0
        class TestStructure(Structure):
            a = FixedLengthField(length=-1)

            class Meta:
                length = 3
Exemple #17
0
        class S(Structure):
            o = FixedLengthField(length=2)
            a = StructureField(Inner)

            class Meta:
                capture_raw = True
Exemple #18
0
 class Struct(Structure):
     byte1 = EnumField(FixedLengthField(1), En)
Exemple #19
0
 class Struct1(Structure):
     b = FixedLengthField(length=lambda c: c._.length, )
Exemple #20
0
 class ShortStructure(Structure):
     text = FixedLengthField(length=3)
Exemple #21
0
 class TestStructure(Structure):
     field1 = FixedLengthField(length=3, offset=2)
Exemple #22
0
 class S(Structure):
     a = FixedLengthField(length=6)
Exemple #23
0
 class UnlimitedFixedLengthStructure(Structure):
     text = FixedLengthField(length=-1)
Exemple #24
0
 class TestStructure(Structure):
     field1 = FixedLengthField(length=3)
     field2 = FixedLengthField(length=2, offset=-3)
Exemple #25
0
 class StructureThatSkips(Structure):
     s = StructureField(ShortStructure, length=5)
     text = FixedLengthField(length=3)
Exemple #26
0
 class TestStructure(Structure):
     field1 = FixedLengthField(length=3)
     field2 = FixedLengthField(length=2, skip=2)
 class TestStruct(Structure):
     length = IntegerField(1)
     content = FixedLengthField(this.length)
Exemple #28
0
        class TestStructure(Structure):
            field1 = FixedLengthField(length=5)
            field2 = FixedLengthField(length=5)

            class Meta:
                checks = [lambda c: c.field1 == c.field2]