【问题标题】:Does apache thrift support function variable as parameter?apache thrift 是否支持函数变量作为参数?
【发布时间】:2016-09-18 19:06:57
【问题描述】:

我想使用FuncType作为foo函数的参数类型。节俭是否支持这一点? FuncType里面怎么定义类型?

struct FuncType {
  // std::function<std::vector<std::pair<int, int>>(const std::string &)>;
  // how to define here?
}

service WorkerService {
  bool foo(1:FuncType func)
}

【问题讨论】:

标签: c++ c++11 rpc thrift idl


【解决方案1】:

Apache Thrift 旨在允许在不同平台和环境之间进行 RPC 调用。所以传递像std::function&lt;int(int)&gt; 这样的东西就不能被支持:C++ 中定义的本机函数如何转移到 JavaScript 中,反之亦然?

(顺便说一句:即使有可能,但出于安全原因,允许服务器用户向 ii 注入一些代码通常是个坏主意)。

如果您想要具有多个处理选项的单个函数 - 创建一些枚举并将其传递给该函数。更好 - 在您的服务中定义多个功能。如果您想真正允许用户逐个样本处理:要么将所有样本返回给用户并在客户端进行相应处理,或者,如果一次通过网络传递的数据太多,提供“迭代器”服务:

struct MyPair {
   i32 first;
   i32 second;
}

typedef i32 QueryId;

service MyService {
  QueryId startProcessing();
  MyPair getNextSample(1: QueryId id);
}

【讨论】:

    猜你喜欢
    • 2011-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多