如何使用Apache Thrift将图像从Python流式传输到C ++ [英] How to stream an image from Python to C++ using Apache Thrift

查看:500
本文介绍了如何使用Apache Thrift将图像从Python流式传输到C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Apache Thrift流式传输文件(图像)? 我搜索了很多有关Thrift的内容,但没有找到任何有关它的书面文档. Facebook为什么要在没有文档的情况下开源该项目?

How could I stream files(images) using Apache Thrift? I have searched a lot about Thrift and did not find any well written documentation regarding to it. Why did Facebook open sourced this project without docs?

推荐答案

我建议的方法是设置服务以分块传递数据,如下所示:

The way I would recommend is to set up your service to deliver data in chunks, like so:

struct DataChunk {
  1 : binary data
  2 : bool haveMoreData
}

service {
  DataChunk  GetChunk( 1 : string resource, 2: i32 offset, 3: i32 size)
}

size限制为某个合理的值(需要在服务器端进行检查),或者完全删除size参数,并始终将固定的,预定义大小的块传递给规避客户要求的巨大数据块.

It seems a good idea to either limit the size to some sane value (needs to be checked on the server side), or remove the size argument at all and always deliver chunks of a fixed, predefined size to circumvent clients asking for insanely large data blocks.

请注意,整个过程需要遵循拉模型,没有内置的推功能.但是,您仍然可以执行推送,您只需要在客户端运行Thrift服务器并传递必要的连接信息即可.尽管这并非在所有情况下(尤其是传输)都行得通,但在可能的情况下,这是一个完全可行的解决方案.

Note that the whole process needs to follow the pull model, there is no built-in push feature. However, you still can do push, you just need to run a Thrift server on the client side and pass the necessary connection info. Although this will not work in all scenarios (especially transports), it is a fully working solution where it is possible.

这篇关于如何使用Apache Thrift将图像从Python流式传输到C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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