apache / apache/brpc

thrift协议支持多参数-讨论

Open
#1,789 2 comments 0 reactions 0 assignees View on GitHub
feature
Dominant language
C++
Stars
17.6k
Forks
4.1k
Avg merge
2d 12h
Merged PRs (30d)
69

Description

**Is your feature request related to a problem? (你需要的功能是否与某个问题有关?)**
当前brpc对thrift协议,仅支持单个参数。thrift协议的多参数形式应用广泛,国内一些公司内部也在使用。希望brpc官方也能支持多参数

**Describe the solution you'd like (描述你期望的解决方法)**
brpc同时支持单参数、多参数

**Describe alternatives you've considered (描述你想到的折衷方案)**

**Additional context/screenshots (更多上下文/截图)**

1). 通过 xxx_args来实现多参数:
1.1. client:

```
example::EchoService_Echo_args real_req;
example::Context context;
example::EchoRequest req2;
example::EchoResponse res;
req2.__set_data("hello");
real_req.context = std::move(context);
real_req.request2 = std::move(req2);
LOG(INFO) << "request data:" << real_req.request2.data;
stub.CallMethod("Echo", &cntl, &real_req, &res, NULL);
```
1.2. server:

```
void ProcessThriftFramedRequest(brpc::Controller* cntl,
brpc::ThriftFramedMessage* req,
brpc::ThriftFramedMessage* res,
google::protobuf::Closure* done) override {
// Dispatch calls to different methods
if (cntl->thrift_method_name() == "Echo") {
return Echo(cntl, req->Cast(),
res->Cast(), done);
}
```
1.3. thrift_protocol.cpp
在 ReadThriftStruct中,直接读,即: xfer += raw_msg->Read(&iprot);
在 ThriftClosure::DoRun中,直接写回:xfer += _response.raw_instance()->Write(&oprot);

这样,可以支持多参数。
然而,对于单个参数,brpc thrift_protocol会对request、response消息进行writeStructBegin、writeFieldBegin、readStructBegin、readFieldBegin等逻辑处理;
对于多参数,xxx_args本身提供的read、write接口应该就已经有了readStructBegin、writeStructBegin等逻辑了。

2). 遇到的问题:
如何和单参数兼容?

Contributor guide

Open the contributing guide

Research direction

Start with thrift_protocol.cpp, especially ReadThriftStruct and ThriftClosure::DoRun, and trace how single-argument requests and responses are encoded. Review the generated *_args structures and the client/server examples in the issue, then determine how compatibility with the existing single-parameter path should be tested. Done means brpc can support both Thrift multi-parameter and single-parameter calls without breaking current behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.