How to stream an image from Python to C++ using Apache Thrift

僤鯓⒐⒋嵵緔 提交于 2019-12-11 00:28:14

问题


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?


回答1:


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

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.

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.



来源:https://stackoverflow.com/questions/26739520/how-to-stream-an-image-from-python-to-c-using-apache-thrift

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