class Foo(Buffer): f_int = int_field(where=bytes_ref[0:4]) f_str = str_field(where=bytes_ref[4:]) def __init__(self, f_int, f_str): self.f_int = f_int self.f_str = f_str
class Foo(Buffer): a = be_int_field(where=bytes_ref[0:1]) s = str_field(where=bytes_ref[1:1 + num_ref(self_ref.calc_s_size(a))]) def calc_s_size(self, a): return a * 2
class Foo(Buffer): f_str_len = int_field(where=bytes_ref[0:4], set_before_pack=lambda self: len(self.f_str)) f_str = str_field(where=bytes_ref[4:4 + f_str_len]) def __init__(self, f_str): self.f_str_len = 0 self.f_str = f_str
class Foo(Buffer): f_int = int_field(where=bytes_ref[0:4], set_before_pack=len_ref(self_ref.f_str) * 2) f_str = str_field(where=bytes_ref[4:4 + f_int // 2])
class Foo(Buffer): f_int = int_field(where=bytes_ref[0:4], set_before_pack=total_size - 4) f_str = str_field(where_when_pack=bytes_ref[4:], where_when_unpack=bytes_ref[4:4 + f_int])
class Foo(Buffer): s = str_field(where=bytes_ref[2:2 + num_ref(self_ref.a)]) a = be_int_field(where=bytes_ref[0:2], set_before_pack=len_ref(s))
class Foo(Buffer): a = be_int_field(where=bytes_ref[0:2]) b = str_field(where=bytes_ref[2:2 + num_ref(self_ref.a)])
class Foo(Buffer): a = str_field(where=bytes_ref[0:2], set_before_pack=' ') b = str_field(where=bytes_ref[2:2 + a])
class Foo(Buffer): l = be_int_field(where=bytes_ref[0:2], set_before_pack=len_ref(self_ref.s)) s = str_field(where=bytes_ref[2:2 + l])
class Foo(Buffer): l = be_int_field(where=bytes_ref[0:2]) s = str_field(where_when_pack=bytes_ref[2:], where_when_unpack=bytes_ref[2:l + 4])
class Foo(Buffer): f_a = str_field(where=bytes_ref[0:8], justify='left', padding=b' ', strip=b'\x00')
class Foo(Buffer): f_a = str_field(where=bytes_ref[0:8], justify='right', padding=b' ')
class Foo(Buffer): f_int = int_field(where=bytes_ref[0:4], set_before_pack=total_size) f_str = str_field(where=bytes_ref[4:f_int])