Sending a stream as a property in Apache Thrift C#

早过忘川 提交于 2019-12-20 02:22:52

问题


I would like to consume a stream in a thrift service, for example, in a service method to have a stream or something similar as an argument to the method (for example, to be able to serialize the result from an IDataReader to a stream, and then deserialize the reference to the data on the other server side).

I don't think that this is explicitly possible, but I was wondering if there was another way to achieve something similar.

Thanks.


回答1:


Apache thrift does not support sending streams. The closest you can get, is send a byte array.

To achieve stream-like experience using thrift, you can create an interface that returns the next part of the stream in a form of byte array.

In C# syntax it would look like

interface MyService
{     
   int OpenStream(string path);

   byte[] ReadNextBlock(int openedStreamId, long maxBlockSize);

}

OpenStream returns "stream id" that is passed to ReadNextBlock on each call. On your server-side you may hold a Dictionary(key - openStreamID, value - Stream) that will be used to keep the source stream open and read next blocks from it.

You can also create a helper class on client side that will be Stream descendant and will use OpenStream and ReadNextBlock to get the actual data.



来源:https://stackoverflow.com/questions/16170377/sending-a-stream-as-a-property-in-apache-thrift-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!