ThriftPyで構造体のリストをバイナリエンコードする最良の方法は何だろうと思っています。私が見つけた唯一の方法は、別のラッパーを作成しstruct
、バイナリのプレフィックス/サフィックスをストリームから削除することですが、これは非常にハックであり、間違いなくより良い方法があるはずです。
foobar.thrift:
struct Object {
1: i32 num1 = 0,
2: i32 num2,
}
struct ListContainer {
1: list<Object> objects
}
app.py
foobar = thriftpy.load('foobar.thrift', module_name="foobar_thrift")
objects = [ ... list of Objects ... ]
thrift_obj = foobar.ListContainer(objects)
trans = TMemoryBuffer()
thrift_obj.write(TBinaryProtocol(trans))
encoded_list = bytes(trans.getvalue())[3:-1]