Skip to content
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

support JsonPrintOptions on RPCContext (currently protobuf only) #171

Merged
merged 3 commits into from
Feb 28, 2022

Conversation

holmes1412
Copy link
Contributor

Support setting JsonPrintOptions through RPCContext. Currently only implement protobuf and will support thrift in the future.

Proto:

syntax="proto3";                                                                
                                                                                
message EchoRequest {                                                           
    string message = 1;                                                         
    string name = 2;                                                            
};                                                                              

message EchoResponse {                                                          
    string message = 1;                                                         
    int32 state = 2;                                                            
    int32 error = 3;                                                            
    repeated Log log = 4;                                                       
};

Usage:

class ExampleServiceImpl : public Example::Service                              
{                                                                               
public:                                                                         
    void Echo(EchoRequest *req, EchoResponse *resp, RPCContext *ctx) override   
    {                                                                           
        resp->set_message("Hi back");                                           
        resp->set_state(1412);
        resp->set_error(0);                                                  
        ctx->set_json_always_print_primitive_fields(true);                      
        ctx->set_json_add_whitespace(true); 
        ...

Origin Output:

{"message":"Hi back","state":1412}

After setting json options on RPCContext:

{
 "message": "Hi back",
 "state": 1412,
 "error": 0,
 "log": []
}

@Barenboim Barenboim merged commit 5db5f82 into sogou:master Feb 28, 2022
@holmes1412 holmes1412 deleted the pb_json_option branch February 22, 2023 05:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants