I have data in a Protocol Buffers format which can be described as follows
message Sections {
repeated Section sections = 1;
}
message Section {
required uint32 type = 1;
required bytes payload = 2;
}
message SectionType1 {
required int32 fieldType1 = 1;
// ...
}
message SectionType2 {
required int32 fieldType2 = 1;
// ...
}
message SectionType3 {
required int32 fieldType3 = 1;
// ...
}
I’m using the protobuf-net library (+ protogen + precompile).
How do I deserialize such data into DTOs similar to
public class Sections
{
public List<Section> Sections { get; }
}
public abstract class Section
{
}
public class SectionType1 : Section
{
public int FieldType1 { get; }
}
public class SectionType2 : Section
{
public int FieldType2 { get; }
}
public class SectionType3 : Section
{
public int FieldType3 { get; }
}
Is it possible to work with such data from .NET (using precompilation since I’m on a light framework)?
To do that, you would have to do it manually – i.e. have
and handle the rest manually. protobuf-net inheritance maps top the following .proto schema:
where we have, say: