Comments (4)
你好。你是说纯的http服务吗?还是http传输的RPC服务(需要写protobuf的那种)。
from srpc.
纯粹的http server是workflow里提供的,这里好像不能使用RPC server相关的操作。
from srpc.
你好,这个和http没有什么关系哈,是因为http里默认用了protobuf转json,然后这个本质是protobuf默认值的用法问题,用JsonPrintOptions可以解决,可以参考这个文档:
https://github.com/sogou/srpc/blob/master/docs/docs-07-srpc-http.md
在protobuf转json的过程中,SRPC在RPCContext上提供了几个接口,支持 JsonPrintOptions。
示例:
class ExampleServiceImpl : public Example::Service
{
public:
void Echo(EchoRequest *req, EchoResponse *resp, RPCContext *ctx) override
{
resp->set_message("Hi back");
resp->set_error(0); // 0是error类型int32在proto3中的默认值
ctx->set_json_always_print_primitive_fields(true); // 带上所有原始域
ctx->set_json_add_whitespace(true); // 增加json格式的空格
}
};
不设置的话,输出如下:
{"message":"Hi back"}
通过RPCContext设置过json options之后的输出:
{
"message": "Hi back",
"error": 0
}
from srpc.
@Barenboim @holmes1412 非常感谢两位的回答, 我想了解的就是srpc如何设置protobuf的默认值, 回答很好的解决了我的疑惑, 非常感谢
from srpc.
Related Issues (20)
- client端访问status code 103 HOT 1
- vs找不到unistd.h文件 HOT 5
- 关于压缩的问题 HOT 2
- problem HOT 29
- New versions of GTest use C++14 HOT 8
- Have Conan package? HOT 1
- crt detected that the application wrote to memory after end of heap buffer HOT 4
- 🎉 srpc tools: simple generator for building Workflow and SRPC projects
- cross compile problem HOT 12
- compile problem HOT 14
- srpc_generator.exe无法使用 HOT 3
- does one service support multi function HOT 7
- Android compile problem HOT 20
- MacOS下链接找不到protobuf HOT 9
- 要求CMake找到一个由“Snappy”提供的包配置文件,但是 CMake没有找到。 HOT 6
- docs/wiki.md第二章图片有误 HOT 1
- Srpc无法正确生成官方hbase.thrift的srpc客户端 HOT 24
- Support in API testing tool linuxsuren/api-testing HOT 7
- srpc和workflow配合使用问题 HOT 19
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from srpc.