发送流作为Apache中节俭C#属性 [英] Sending a stream as a property in Apache Thrift C#

查看:130
本文介绍了发送流作为Apache中节俭C#属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想消耗在一个节俭服务的流,例如,在服务的方法有一个流或作为参数类似的方法(例如,能够从一个IDataReader的序列的结果,以流,然后反序列化的另一服务器端的参照数据)。

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.

感谢。

推荐答案

阿帕奇节俭不支持发送流。你可以得到最接近的,是发送一个字节数组。

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.

在C#语法它看起来像

interface MyService
{     
   int OpenStream(string path);

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

}



的OpenStream返回传递流ID来ReadNextBlock上每次调用。在服务器端,你可以持有词典(键 - openStreamID,价值 - 流),将用于保持源流开放并从中读取下一个块

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.

你也可以创建客户端一个辅助类,这将是流后裔,并且使用的OpenStream和ReadNextBlock获取的实际数据。

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.

这篇关于发送流作为Apache中节俭C#属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆