Skip to content

support embedding message #752

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

Closed
unlikezy opened this issue Nov 16, 2018 · 2 comments
Closed

support embedding message #752

unlikezy opened this issue Nov 16, 2018 · 2 comments

Comments

@unlikezy
Copy link

unlikezy commented Nov 16, 2018

My request might be similar to #192
Given the proto definition:

synatx = "proto3";
package test;
message Req1 {
    string user_id = 1;
    uint64 timestamp = 2;
    uint64 region_id = 3;
     string req1_fff1 = 10;
     string req1_fff2 = 11;
}
message Req2 {
    string user_id = 1;
    uint64 timestamp = 2;
    uint64 region_id = 3;
     string req2_fff1 = 10;
     string req2_fff2 = 11;
}
// more reqs definition....

As you can see, every Req definition needs some common fileds(1~3).
I have to repeate them(might be a lot) in every message.
You might suggest to seperate these fields into a new message, like this:

message CommonFields {
    string user_id = 1;
    uint64 timestamp = 2;
    uint64 region_id = 3;
}
message Req1 {
     CommonFields common_fields = 1;
     string req1_fff1 = 10;
     string req1_fff2 = 11;
}
message Req2 {
     CommonFields common_fields = 1;
     string req2_fff1 = 10;
     string req2_fff2 = 11;
}

But we are using grpcgateway, and the json proto is required by our company MUST be the former way:
(there might be a lot other reasons for people need proto be in this way)

message Req1 {
    string user_id = 1;
    uint64 timestamp = 2;
    uint64 region_id = 3;
     string req1_fff1 = 10;
     string req1_fff2 = 11;
}

The problem will be well solved if protobuf provide a syntax suger like this:

message Req1 {
      CommonFields;
     string req1_fff1 = 10;
     string req1_fff2 = 11;
}

what protoc should do is to treat this definition as below:

message Req1 {
    string user_id = 1;
    uint64 timestamp = 2;
    uint64 region_id = 3;
     string req1_fff1 = 10;
     string req1_fff2 = 11;
}

This solution seems quite straightforward.

@unlikezy
Copy link
Author

unlikezy commented Nov 16, 2018

it might be better to put this request on https://github.com/protocolbuffers/protobuf
and I did do it : protocolbuffers/protobuf#5372
but I still keep this issue here.

@neild
Copy link
Contributor

neild commented Nov 16, 2018

Yes, this request is best filed against https://github.com/protocolbuffers/protobuf. Closing this one as a duplicate.

@neild neild closed this as completed Nov 16, 2018
@golang golang locked and limited conversation to collaborators Jun 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants