예제 #1
0
class Garzon(h.Struct):
    arr = h.Array(field_type=h.UInt8(3), length=3, value=(1, 2), fill=True)
    nested_vla_len = h.UInt16()
    nested_vla = h.Vector(field_type=h.Int32(),
                          length=nested_vla_len,
                          value=(9, 10, 100))
    x = h.UInt8(5)
예제 #2
0
class Shine(h.Struct):
    arr = h.Array(field_type=h.UInt8(3), length=3, value=(1, 2), fill=True)
    vec_len = h.UInt8()
    vec = h.Vector(field_type=h.UInt8(), length=vec_len)
    y = h.UInt64(9)
    z_len = h.UInt8()
    z = h.Vector(field_type=Garzon(), length=z_len, value=[
        Garzon(nested_vla=(11, 12, 13, 14, 15)), Garzon(arr=(9,)), Garzon()])
    vec2_len = h.UInt8()
    vec2 = h.Vector(field_type=h.UInt32(), length=vec2_len, value=(53, 99, 123))
    x = h.UInt16(104)
예제 #3
0
    class Ronen(h.Struct):
        x = h.UInt8(2)
        arr = h.Array(10, h.FieldPlaceholder, value=list(range(10)))

        @h.Struct.from_bytes_hook(arr)
        def foo(self):
            self.arr.type = h.UInt16()
예제 #4
0
class Gilad(h.Struct):
    i8 = h.Int8(0)
    i16 = h.Int16(0)
    i32 = h.Int32(0)
    i64 = h.Int64(0)

    u8 = h.UInt8(0)
    u16 = h.UInt16(0)
    u32 = h.UInt32(0)
    u64 = h.UInt64(0)

    flt = h.Float(0)
    dub = h.Double(0)
예제 #5
0
class Atedgi(h.Struct):
    this = h.UInt8(1)
    aviv = h.FieldPlaceholder()

    def __init__(self, this=1, *args, **kwargs):
        self.this = this
        self.set_vec_field()
        super().__init__(*args, **kwargs)

    @h.from_bytes_hook(aviv)
    def set_vec_field(self):
        d = {len(x()): x for x in (h.UInt8, h.UInt16, h.UInt32, h.UInt64)}
        self.aviv = d[self.this.value]()
예제 #6
0
class IDVector(h.Struct):
    vec_len = h.UInt16()
    id_len = h.UInt8()
    vec = h.Vector(vec_len, h.FieldPlaceholder)  # Vector of IDs

    def __init__(self, id_type: Type[Field] = h.FieldPlaceholder, *args, **kwargs):
        self.vec.type = id_type()
        self.id_len = len(self.vec.type)
        super().__init__(*args, **kwargs)

    @h.from_bytes_hook(vec)
    def set_vec_field(self):
        d = {len(x()): x for x in (h.UInt8, h.UInt16, h.UInt32, h.UInt64)}
        self.vec.type = d[int(self.id_len)]()
예제 #7
0
class Isaac(h.Struct):
    arr = h.Array(field_type=h.UInt8(3), length=3, value=(1, 2), fill=True)
    x = h.UInt8(5)
예제 #8
0
 class NadavLoYazam(h.Struct):
     nadav = h.UInt8()
     lo = h.UInt16()
     yazam = h.UInt32()
     bihlal = h.UInt64()
예제 #9
0
def test_comparisons():
    assert h.UInt16(3) > h.UInt16(2)
    assert h.UInt16(3) == h.UInt16(3)
    assert h.UInt16(4) == h.UInt8(4)
예제 #10
0
class MyStructBody(h.Struct):
    b = h.UInt8(2)
    c = h.UInt8(3)
예제 #11
0
 class Shustin(h.Struct):
     length = h.UInt16()
     data = h.Vector(length=length, field_type=h.UInt8())
예제 #12
0
def test_add():
    assert h.UInt8(2) + 3 == 5
    assert 2 + h.UInt8(3) == 5
    assert h.UInt8(2) + h.UInt16(3) == 5
예제 #13
0
class MyStructFooter(h.Struct, footer=True):
    d = h.UInt8(4)
예제 #14
0
class FooterBody1(h.Struct):
    x = h.UInt8(0xFF)
예제 #15
0
class Card(h.Struct):
    value = h.UInt8()
    suit = h.UInt8()
예제 #16
0
 class BadStruct(h.Struct):
     a = h.UInt8(validator=2)
예제 #17
0
 class Becca(h.Struct):
     x = h.UInt8()
예제 #18
0

def test_struct_meta_len():
    # noinspection PyTypeChecker
    assert len(Omri()) == len(Omri)


def test_field_copy():
    x = Omri()
    x.a = 3
    y = Omri()
    assert x.a == 3
    assert y.a == 256


@pytest.mark.parametrize('field', (h.UInt8, h.UInt8(), 3))
def test_redefining_fields(field):
    with pytest.raises(NameError):
        # noinspection PyUnusedLocal
        class Check(Omri):
            a = field


def test_bytes_length():
    assert len(bytes(Omri())) == 11


def test_non_default_args():
    class Check(h.Struct):
        x = h.UInt8()
예제 #19
0
 class Good(h.Struct):
     i32 = h.Int32(5, validator=lambda z: z > 4)
     i32_range = h.Int32(14, validator=range(0, 30, 2))
     i32_set = h.Int32(2, validator={1, 2, 3})
     i32_arr = h.Array(length=5, field_type=h.UInt8(5), validator=5)
예제 #20
0
class Tst(h.Struct):
    a = h.UInt8(validator=0)
예제 #21
0
 class Shustin2(h.Struct):
     arr = h.Array(3, h.UInt8(8), validator=lambda x: x > 9, fill=True)
예제 #22
0
    class Check(h.Struct):
        x = h.UInt8()

        def __init__(self, a):
            super().__init__(a)
            self.x = a
예제 #23
0
class Tomer(h.Struct):
    b = h.UInt8(5)
    c = h.Double(3)
예제 #24
0
class Omri(h.Struct):
    a = h.UInt16(256)
    b = h.UInt8(5)
    c = h.Double(3)
예제 #25
0
class Log(h.Struct):
    data = h.UInt8(2)
    time = Time()
예제 #26
0
class MyStructHeader(h.Struct):
    a = h.UInt8(1)