Sending a stream as a property in Apache Thrift C#

后端 未结 1 380
醉话见心
醉话见心 2021-01-20 06:31

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

相关标签:
1条回答
  • 2021-01-20 06:59

    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.

    0 讨论(0)
提交回复
热议问题