コード例 #1
0
ファイル: test_builder.py プロジェクト: xeondriving/capnpy
 def test_null_pointers(self):
     NULL = b'\x00\x00\x00\x00\x00\x00\x00\x00' # NULL pointer
     buf = SegmentBuilder()
     pos = buf.allocate(24)
     buf.copy_from_struct(0, Struct, None)
     buf.alloc_text(8, None)
     buf.copy_from_list(16, PrimitiveItemType(Types.int64), None)
     s = buf.as_string()
     assert s == NULL*3
コード例 #2
0
ファイル: test_builder.py プロジェクト: xeondriving/capnpy
 def test_alloc_text_and_data(self):
     buf = SegmentBuilder()
     buf.allocate(32)
     buf.alloc_text(0, b'foo')
     buf.alloc_text(8, None)
     buf.alloc_text(16, b'bar')
     buf.alloc_data(24, b'bar')
     s = buf.as_string()
     print()
     print_buffer(s)
     assert s == b('\x0D\x00\x00\x00\x22\x00\x00\x00'    # ptr to 'foo'
                   '\x00\x00\x00\x00\x00\x00\x00\x00'    # NULL
                   '\x09\x00\x00\x00\x22\x00\x00\x00'    # ptr to text 'bar' (4 items)
                   '\x09\x00\x00\x00\x1A\x00\x00\x00'    # ptr to data 'bar' (3 items)
                   'foo\x00\x00\x00\x00\x00'
                   'bar\x00\x00\x00\x00\x00'
                   'bar\x00\x00\x00\x00\x00')