-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rpc 空参数 的支持 #120
Comments
你好~目前srpc生成工具: 但有个很简单的方法,不需要自己修改生成RPC函数,把文件按照对应的路径拷贝到咱们要生成的位置即可,我试过可行~以tutrorial中为例: 我们的目标proto文件在 tutorial/echo_pb.proto 由于执行的路径是tutorial/下, cd tutorial
../_bin/srpc_generator protobuf echo_pb.proto ./ |
我试试看,主要是空参数 不想函数有任何参数。 |
我看了下,这个文件里注释有说明,用了empty的这个Message,是让我们可以这样定义rpc:
这个函数也是有参数的吧,只不过是空的而已? |
是的,可以这样定义。但是SRPC生成出来的C++代码是: class Service : public srpc::RPCService
{
public:
// please implement these methods in server.cc
virtual void Bar(google::protobuf.Empty *request, google::protobuf.Empty *response, srpc::RPCContext *ctx) = 0;
public:
Service();
}; 想要的效果是: class Service : public srpc::RPCService
{
public:
// please implement these methods in server.cc
virtual void Bar(srpc::RPCContext *ctx) = 0;
public:
Service();
}; |
可是我用protoc生成出来的service接口,也是带着参数的呀,如下: class Foo_Stub : public Foo {
public:
// implements Foo ------------------------------------------
void Bar(::PROTOBUF_NAMESPACE_ID::RpcController* controller,
const PROTOBUF_NAMESPACE_ID::Empty* request,
PROTOBUF_NAMESPACE_ID::Empty* response,
::google::protobuf::Closure* done);
}; 这个没有参数的rpc函数的需求如果protobuf支持,我可以后续找时间支持一下。要不然srpc还是按照官方建议的来哈~ |
Protobuf应该是支持。可以看一下。 |
嗯,我用 |
嗯,加了后生成跟你的一致的。 client.Bar(nullptr,[](google::protobuf.Empty *response, srpc::RPCContext *ctx)
{
// Do something
}); |
应该会挂,因为很难定义这种情况下程序的行为。 |
我测试了,跟进了代码。在Windows下,nullptr 传进去调用没问题,最终表现正常。 |
那应该是pb把nullptr序列化成全都是默认值request发送出去。 |
ProtocolBuf 自带了EmptyParam 的支持,但是在proto文件中使用导入,SRPC生成的时候报找到不到 google/protobuf/empty.proto。
所以,如何让SRPC支持空参数?
自己修改生成的RPC函数应该可以实现,但是很多地方都要修改。
对了,生成的是C++语言的。
The text was updated successfully, but these errors were encountered: