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条)

报告相同问题?