I think the typical way to do this would be to just store CommonParams as a
submessage in each of your request types. The one problem is that this
means the fields would not be at the top-level of the JSON as you wanted to
have. So I think you have to choose to either go with this approach and
live with an extra layer of nesting, or else duplicate the fields at the
top level of each request type.

On Wed, May 17, 2017 at 6:11 AM, Ciprian Caba <caba.cipr...@gmail.com>
wrote:

> Hi guys,
>
> I want to use protobufs on c++ for directly serializing some server
> requests into data objects. However, these requests share some common
> fields (eg: ts, auth-key, so on) - let's call them CommonParams
>
> I will have multiple requests, eg: CreateAccountRequest,
> ReadAccountRequest, DeleteAccountRequest, which will all share the above
> common fields plus more.
>
> Is there a way to merge a CommonParams's fields into a
> CreateAccountRequest, ReadAccountRequest? I also want the params to be on
> top level of the serialized JSON so no custom field of type CommonParams.
>
> The only way I found was to serialize the CommonParams message and then to
> parse a new *Request message by parsing that serialized CommonParams. Of
> course, this means duplicating the CommonParams's fields into all of the
> *Request messages.
>
> Any thoughts?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at https://groups.google.com/group/protobuf.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to