TProtocols 之间的转换
我想从 TBinaryProtocol 转换为 TSimpleJSONProtocol,以便我可以以更人类可读的方式显示记录的二进制 thrift 请求流。我对流中的服务请求特别感兴趣,因此使用 TDeserializer 不是一个选项(我也希望保持代码对于正在使用的特定 Thrift 服务/对象是通用的。
有没有办法直接转换将 TBinaryProtocol 对象转换为 TSimpleJSONProtocol,而不需要构造 Thrift 对象的中间步骤?
I'd like to convert from TBinaryProtocol to TSimpleJSONProtocol, so that I can display a recorded stream of binary thrift requests in a more human-readable fashion. I'm particularly interested in the service requests in the stream, so using the TDeserializer isn't an option (I'm also hoping to keep the code generic wrt the particular Thrift service/objects being used.
Is there a way to directly convert the TBinaryProtocol object to TSimpleJSONProtocol without the intermediate step of constructing a Thrift object?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
协议与数据完全无关。你的问题就像问,我可以将 HTTP 协议转换为 FTP 协议而不进行任何类型的解码吗?我严重怀疑这一点,尽管我以前就错了。
完全使用 JSON 协议会容易得多。这就是节俭——改变这一点实际上只是一句简单的话。众所周知,二进制协议很难调试,为了您自己的理智,请切换到其他协议。当一切看起来都正常时,切换回二进制。
A protocol has absolutely nothing to do with the data. Your question is like asking, can I convert the HTTP protocol to an FTP protocol without doing any kind of decoding. I seriously doubt it, although I've been wrong before.
It would be far easier to simply use the JSON protocol all the way through. It's thrift -- changing that is literally a one-liner. The binary protocol is notoriously difficult to debug, switch to something else for your own sanity. Switch back to binary when everything seems to be working.