The schema-generation code currently produces flat output; if you want nested output, you can simply edit the generated schema.
Nesting messages when serializing using protobuf-net
-
03-10-2022 - |
Question
I have a requirement to produce protocol buffer output in this form:
message TimeSeries {
message Point {
required int64 DateTime = 1;
required double Value = 2;
}
repeated Point Points = 3;
}
In C#, no matter whether I define the TimeSeries and Point classes separately or with Point as a nested class, I cannot get the resultant output from calling Serializer.GetProto to produce this hierarchy.
This was what I assumed would produce the desired results:
[ProtoContract]
public class TimeSeries
{
[ProtoMember(1, IsRequired = true)]
public List<Point> Points { get; set; }
[ProtoContract]
public class Point
{
[ProtoMember(1, IsRequired = true)]
public Int64? DateTime { get; set; }
[ProtoMember(2, IsRequired = true)]
public Double? Value { get; set; }
}
}
Instead I get:
message Point {
required int64 DateTime = 1;
required double Value = 2;
}
message TimeSeries {
repeated Point Points = 1;
}
I am new to protocol buffers and protobuf-net, so may well be missing something obvious.
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow