def test_compact_structs(self):
schema = """
@0xbf5147cbbecf40c1;
struct Person {
name @0 :Text;
}
struct Foo {
key @0 :Person;
}
"""
mod = self.compile(schema)
buf = b('garbage0'
'\x05\x00\x00\x00\x32\x00\x00\x00' # ptr to name
'garbage1'
'dummy\x00\x00\x00')
p = mod.Person.from_buffer(buf, 8, 0, 1)
foo = mod.Foo(p)
assert foo.key.name == b'dummy'
# we check that the structure has been packed
assert foo.key._data_offset == 8
assert foo.key._seg.buf[8:] == b('\x01\x00\x00\x00\x32\x00\x00\x00' # ptr to dummy
'dummy\x00\x00\x00')
评论列表
文章目录