Hi everyone,

I think that protobuf is very cool and would like to use inheritance with 
it, but I know that there's not inheritance in protobuf.
Note : I use proto2 and I already know that there is "extensions" from 
proto2, *but I don't want to use it* because it will be deprecated for 
proto3.

So I think to use this pattern :
*message *Parent {
    // Base fields for Parent and A/B/C (Child messages)
    *optional *int32 field1 = 1;
    *optional *int32 field2 = 2;

    *enum *ChildType {
        T_A = 0;
        T_B = 1;
        T_C = 2;
        // Add more "T_" in the future
    }

    *message *A {
        *required *int32 a1 = 1;
        *required *int32 a2 = 2;
    }

    *message *B {
        *required *int32 b1 = 1;
    }

    *message *C {
        *required *int32 c1 = 1;
    }

    // Add more message (D, E, F etc) in the future


    // Childs
    *required *ChildType type = 3; // Choosing child from this field
    *optional *A a = 4;
    *optional *B b = 5;
    *optional *C c = 6;

    // Add more child fiels in the future
}

*So here are my questions : *
1. Is there a better pattern which is *compatible with proto3* for my 
problem ? Can you give an example of it ?
2. I chose only int32 for my example, so if I serialize a Parent object 
with only *C type message initialized* (A and B are *null*), what will be 
the size of my serialized file ?
    2a. Size will be => [2 int32 from Parent + 1 int32 from enum + 2 int32 
from A + 1 int32 from B + 1 int32 from C] = 7 -> 7 x 32 bits = 224 bits = *28 
bytes*. 
    2b. Size will be => [2 int32 from Parent + 1 int32 from enum + 1 int32 
from C] = 4 -> 4 x 32 bits = 128 bits = *16 bytes*. 
    2c. Give your detailed answer.


Best Regards,

-- 
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 http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to