Q1ngbo commented on code in PR #3196:
URL: https://github.com/apache/brpc/pull/3196#discussion_r2745856479
##########
example/benchmark_fb/test.fbs:
##########
@@ -0,0 +1,24 @@
+namespace test;
+
+table BenchmarkRequest {
+ opcode:int;
+ echo_attachment:int;
+ attachment_size:long;
+ request_id:long;
+
+ reserved:long;
+ message:string;
+}
+
+table BenchmarkResponse {
+ opcode:int;
+ echo_attachment:int;
+ attachment_size:long;
+ request_id:long;
+ reserved:long;
+ message:string;
+}
+
+rpc_service BenchmarkService {
Review Comment:
> fb 是否可以这样使用,显式的在 method 后指定 index?
好主意!我可以修改下flatc。但为了兼容flatbuffers语法,fbs文件里需要这么写
```
rpc_service BenchmarkService {
Test(BenchmarkRequest):BenchmarkResponse (id: 2);
Test2(BenchmarkRequest):BenchmarkResponse (id: 5);
Test3(BenchmarkRequest):BenchmarkResponse (id: 1);
}
```
最终可以在test.brpc.fb.cpp中生成如下代码。
```
switch (method->index()) {
case 2:
Test(controller, request, response, done);
break;
case 5:
Test2(controller, request, response, done);
break;
case 1:
Test3(controller, request, response, done);
break;
default:
std::cout << "ERROR: " << "Bad method index; this should never happen."
<< std::endl;
break;
}
```
这样后续任意删除method也能保持兼容性,而且不需要修改brpc中的处理逻辑
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]