Hi All,
I am very new to thrift.
I have written a AddressBook.thrift file. This file has a following
structure:
Struct A {
1: required list<string> str1,
2: required i32 int1,
3: required i64 int2
}
Struct B {
1: required list<A> a1,
2: required bool bool1
}
Struct C {
1: required list<B> b1
}
I compile this thrift file using python compiler.
Then I create a python server (addressBookServer.py) which add/modifies
2-3 entries in b1 (which is list of B). Then it serializes it into
binary format using:
address_book =new AddressBook()
transport = TSocket.TServerSocket('localhost', 9090)
tfactory = TTransport.TBufferedTransportFactory()
pfactory = TBinaryProtocol.TBinaryProtocolFactory()
server = TServer.TSimpleServer(processor, transport, tfactory, pfactory)
transportOut = TTransport.TMemoryBuffer()
protocolOut = TBinaryProtocol.TBinaryProtocol(transportOut)
address_book.write(protocolOut)
bytes = transportOut.getvalue()
Then it writes to the text file:
f = open(file_name, "wb")
f.write(bytes)
f.close()
While trying to convert to binary format, I get following error:
address_book.write(protocolOut)
File "gen-py/addressBook/ttypes.py", line 267, in write
oprot.writeListBegin(TType.STRUCT, len(self.b1))
AttributeError: B instance has no attribute '__len__'
On debugging I found out that in generated file ttypes.py where all user
defined data types (struct in AddressBook.thrift) are defined, there is
no _len_ (self)/ len() method defined.
I am stuck over here as to how to proceed further. Can someone please
guide me through it.
Regards,
Surbhi