test_misc.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:capnpy 作者: antocuni 项目源码 文件源码
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')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号