Thriftpy / thriftpy2

Pure python approach of Apache Thrift.
MIT License
567 stars 90 forks source link

How to decode some data without IDL files that encoding by Apache thrift TBinaryProtocol? #210

Closed xf97 closed 5 months ago

xf97 commented 1 year ago

Hello colleagues from Eleme, this is Jia Mao from Ant Group. I have a question about how to use this library and would like to consult with you. I currently have some data that is encoded using Apache Thrift TBinaryProtocol, but I don't have the corresponding IDL files. However, from what I understand, Apache Thrift TBinaryProtocol is a self-describing protocol, so I should still be able to decode this data. I found some files in the code such as /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/thriftpy2/protocol/binary.py and thriftpy2/protocol/binary.py, and methods such as read_struct, read_message_begin, and read_message_end seem to be able to help me solve the problem, but I don't know how to use them. Could you please help me with this issue? Thank you very much!

xf97 commented 1 year ago

In my understanding, there should be a one-click decoding interface, such as raw_data = thriftpy.TBinaryProtocol().decode(bytes_data), because similar functionality should also be used in this lib. Even if it does not exist, this functionality can be easily composed through several sub-interfaces. However, I have not found detailed documentation to explain this problem.

ethe commented 1 year ago

According to the layout format definition of Apache Thrift, it could be possible that decode message without IDL. However, it is not the objective of thriftpy, so we have no intention of this.

aisk commented 1 year ago

As a recommendation, you can use wiresharek to capture the thrift request and got the structured response, and use this to got the IDL.