I have two classes that I would like to transform to protobuf messages:
[ProtoContract]
class ClassA {
[ProtoMember(1)]
public int b;
[ProtoMember(2)]
public int c;
}
[ProtoContract]
class ClassD : ClassA
{
[ProtoMember(3)]
public int e;
[ProtoMember(4)]
public int f;
}
What I am trying to achieve is a serialization of ClassA containing b and c. And when serializing ClassD i will get b, c, e and f.
Is this possible, or what kind of approach should I use? I’m trying to avoid nested messages.
Using my approach I get a problem when serializing a ClassD object.
ClassD d = new ClassD();
Serialize.Serialize<ClassA>(stream, d);
Serialize.Serialize<ClassD>(stream, d);
In both attempts above the serialized data only contain the properties in ClassD and none from ClassA.
I would expect at least none of the properties in ClassD to be serialized in the first case
and I would like all, both from ClassA and ClassD to be serialized in the second case.
How would I approach this problem?
It looks like this works in v2 without inheritance:
These will each be flat models, not nested. At the moment this would need explicit setup (as above), as it isn’t part of how it builds the model by default – but as a corollary you don’t need attributes here: