Understood but this is not what I wanted in the first place. 

Does someone has any idea about what makes it difficult to implement this? 
Also, is there a clever way to have the same behaviour?
Basically, here I want to avoid copy pasting same fields over and over 
again (makes code less maintainable).

Any ideas are welcome.

On Thursday, October 20, 2016 at 1:33:04 AM UTC+5:30, Feng Xiao wrote:
>
> I meant something like:
>
> message Header {
>   string account = 1;
>   string symbol = 1;
> }
>
> message Msg1 {
>   Header header = 1;
>   ...
> }
>
> message Msg2 {
>   Header header = 1;
>   ...
> }
>
> On Wed, Oct 19, 2016 at 12:42 PM, Saurabh Kumar <saurab...@gmail.com 
> <javascript:>> wrote:
>
>> Thanks for the reply. What exactly do you mean by common header?
>>
>> On Thu, 20 Oct 2016 at 1:06 AM, Feng Xiao <xiao...@google.com 
>> <javascript:>> wrote:
>>
>>>
>>>
>>> On Wed, Oct 19, 2016 at 4:03 AM, Saurabh Kumar <saurab...@gmail.com 
>>> <javascript:>> wrote:
>>>
>>>> Hi,
>>>>
>>>> This question is regarding inheritance in protobuf C++ library. I will 
>>>> explain what I am looking for with a concrete example.
>>>>
>>>> I have this message definition:
>>>>
>>>>  message MSG1
>>>>  {
>>>>    required string account = 0;
>>>>    required string symbol = 1;
>>>>  }
>>>>
>>>> Now I want to extend this message and define a new message like this:
>>>>  message MSG2
>>>>  {
>>>>    required string account = 0;
>>>>    required string symbol = 1;
>>>>    required int32  id          = 2;
>>>>  }
>>>>
>>>> You will notice that first two fields of MSG2 are exactly same as MSG1 
>>>> (they are intended to be like that). But here I had to copy paste the 
>>>> common fields again.
>>>> Can I do something like this?
>>>>
>>>>  message MSG2 extends MSG1
>>>>  {
>>>>    required int32  id          = 2;
>>>>  }
>>>>
>>>> I have already thought about using it like:
>>>>  message MSG2
>>>>  {
>>>>    required MSG1 msg1 = 0;
>>>>    required int32  id          = 2;
>>>>  }
>>>> But this is not really what I want.
>>>>
>>>> What's the best way to achieve this?
>>>>
>>> Protobuf doesn't support inheritance. Having a common header and using 
>>> composition is the best solution.
>>>  
>>>
>>>>
>>>> Thanks,
>>>> Saurabh
>>>>
>>> -- 
>>>> 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+u...@googlegroups.com <javascript:>.
>>>> To post to this group, send email to prot...@googlegroups.com 
>>>> <javascript:>.
>>>> 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+u...@googlegroups.com <javascript:>.
>> To post to this group, send email to prot...@googlegroups.com 
>> <javascript:>.
>> 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