doutangkao2789 2012-08-15 22:36
浏览 68
已采纳

使用自己的apache thrift通信协议?

I was wondering if it's possible to just use the serialization portions of apache thrift.

I basically have a custom communication protocol already created, and would like to pass a thrift object from my server (PHP) to the client (C#).

My home-grown communication protocol is basically JSON. I wanted to use thrift to construct the object properly on the PHP side, then send it through JSON where my C# app would then re-construct the object using the classes generated by thrift --gen csharp myfile.thrift

Does anyone know if this is possible or where I would get started? Would I overload TProtocol somehow?

  • 写回答

2条回答 默认 最新

  • dougaimian1143 2012-10-29 11:21
    关注

    Yes, you can use Thrift just for the object definitions. We do something similar, although instead of using JSON we use a binary format.

    You could extend TProtocol, or you could just have your own class interrogate the Thrift object you have created and pull out and encode your fields. Then when you receive the JSON, simply create a new Thrift object from the values you have received.

    Depending on how you implement it, and how good the client libraries are for C# and PHP (I haven't used either), you might be able to implement this in a way so you do not have to change your code when you change your schema, although you will still have to generate the Thrift objects and deploy them. Basically you walk through the objects and encode each item in JSON. We did this in Java.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!