GithubHelp home page GithubHelp logo

Comments (4)

Barenboim avatar Barenboim commented on May 29, 2024

你好。你是说纯的http服务吗?还是http传输的RPC服务(需要写protobuf的那种)。

from srpc.

Barenboim avatar Barenboim commented on May 29, 2024

纯粹的http server是workflow里提供的,这里好像不能使用RPC server相关的操作。

from srpc.

holmes1412 avatar holmes1412 commented on May 29, 2024

你好,这个和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.

archliu321 avatar archliu321 commented on May 29, 2024

@Barenboim @holmes1412 非常感谢两位的回答, 我想了解的就是srpc如何设置protobuf的默认值, 回答很好的解决了我的疑惑, 非常感谢

from srpc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.