I think it can result in in-efficiencies. One of the core feature of 
porto-buffers is to pack things efficiently. The lower value of integer 
assigned to a variable ensures optimised packing and secondly the integers 
have to be unique but not necessarily continuous.
With multiple level of inheritance, it will be difficult to keep track of 
the integers assigned to properties in the base structures.

On Tuesday, 25 October 2016 02:26:07 UTC+5:30, Dov Wasserman wrote:
>
> Hello, Saurabh. I understand what you're trying to do, and that it seems 
> to make perfect sense. Every instance of a Msg2 also has all the fields of 
> a Msg1, so why can't it be a special subtype with just some extra data? 
> Ploymorphism is meant primarily for types where the difference among 
> parents and subtypes is behavior, but not for differering data fields. See 
> here <https://en.wikipedia.org/wiki/Circle-ellipse_problem> for a more 
> detailed explanation why. 
>
> On Wednesday, October 19, 2016 at 3:30:22 PM UTC-4, Saurabh Kumar 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?
>>
>> 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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to