Esempio n. 1
0
def test_substruct_member_assignment() -> None:
    pos_t = create_struct('Pos', {
        'x': UInt16,
        'y': UInt16,
    })
    size_t = create_struct('Size', {
        'width': UInt8,
        'height': UInt8,
    })
    rect_t = create_struct('Rect', {
        'pos': pos_t,
        'size': size_t,
    })
    rect1: Any = rect_t(0)
    rect2: Any = rect_t(0)
    rect1['pos']['x'] = 0x0123
    rect1['pos']['y'] = b'\x67\x45'
    rect1['size']['width'] = UInt8(0x11)
    rect1['size']['height'] = 0x22
    rect2['pos']['x'] = 0x89AB
    rect2['pos']['y'] = 0xCDEF
    rect2['size']['width'] = 0x33
    rect2['size']['height'] = 0x44
    assert bytes(rect1) == b'\x23\x01\x67\x45\x11\x22'
    assert bytes(rect2) == b'\xAB\x89\xEF\xCD\x33\x44'
Esempio n. 2
0
def test_substruct_member_assignment() -> None:
    class Pos(Struct):
        x: UInt16
        y: UInt16

    class Size(Struct):
        width: UInt8
        height: UInt8

    class Rect(Struct):
        pos: Pos
        size: Size

    rect1 = Rect(0)
    rect2 = Rect(0)
    rect1.pos.x = 0x0123
    rect1.pos.y = b'\x67\x45'
    rect1.size.width = UInt8(0x11)
    rect1.size.height = 0x22
    rect2.pos.x = 0x89AB
    rect2.pos.y = 0xCDEF
    rect2.size.width = 0x33
    rect2.size.height = 0x44

    assert bytes(rect1) == b'\x23\x01\x67\x45\x11\x22'
    assert bytes(rect2) == b'\xAB\x89\xEF\xCD\x33\x44'
Esempio n. 3
0
 class SomeStruct(Struct):
     _pad1 = Padding(2)
     field1 = UInt8()
     field2 = UInt16()
     _pad2 = Padding(1)
     _pad3 = Padding(1)
     field3 = UInt16()
     _pad4 = Padding(2)
 class Rect(Struct):
     x = UInt16()
     y: UInt16
     width: UInt8
     height = UInt8()
Esempio n. 5
0
 class UnionE(Union):
     field1 = UInt8()
     field2 = uint16_clone()
Esempio n. 6
0
 class Child2(Struct):
     field2_1 = UInt8()
     field2_2 = UInt16()
     field2_3 = UInt8()
Esempio n. 7
0
 class Child1(Struct):
     field1_1 = UInt16()
     field1_2 = UInt8()
     field1_3 = UInt8()
Esempio n. 8
0
 class Data(Union):
     u16: UInt16
     u8 = UInt8()
Esempio n. 9
0
 class Child(Struct):
     field1 = UInt16()
     field2 = UInt8()
     field3 = UInt8()
Esempio n. 10
0
 class Data(Union):
     u16 = UInt16()
     pos = Pos()
     u8 = UInt8()
Esempio n. 11
0
 class StructE(Struct):
     field1 = UInt8()
     field2 = uint16_clone()
Esempio n. 12
0
 class Rect(Struct):
     pos = Pos()
     width = UInt8()
     height = UInt8()