我具有可以如下协议缓冲器.NET继承
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;
// ...
}
我使用的protobuf网库(+硫辛酸+预编译)来描述在协议缓冲区格式的数据。 我如何反序列化这样的数据转换成类似
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; }
}
的DTO是否有可能与.NET这样的数据的工作(使用预编译,因为我在一个小型框架)?
协议缓冲区用于序列化信息 - 以平面和顺序的方式。你应该将任何类型的东西都看作“形状”,只包含数据,不包含继承或行为。请参阅数据传输对象。 –