Protobuf-net v2 C Circular Links

As far as I know, protobuf-net, starting with version v2, supports links.

I am currently trying to use it in a data structure where circular references may occur as follows:

[ProtoContract]
internal class WaypointDatabase
{
  [ProtoMember(1)]
  public List<Waypoint> Waypoints { get; set; }
}

[ProtoContract(AsReferenceDefault = true)]
internal class Waypoint
{
  [ProtoMember(1)]
  public string Ident { get; set; }

  [ProtoMember(2)]
  public List<Route> Routes { get; set; }
}

[ProtoContract]
internal class Route
{
  [ProtoMember(1)]
  public Waypoint PreviousWaypoint { get; set; }

  [ProtoMember(2)]
  public Waypoint NextWaypoint { get; set; }
}

Thus, the main object that is serialized with protobuf-net is an instance WaypointDatabase. This object contains Waypointsa list Routesthat again refers to Waypoints.

The reason I want to use this data structure is because there are waypoints that are not included in / link to the route. Therefore, I need this waypoint database to track all waypoints, regardless of whether they are in existing routes or not.

WaypointDatabase protobuf-net, StackOverflowException, , , Waypoint AsReferenceDefault, , protobuf-net , ( ).

?

,

. S.: 2.0.0.668 protobuf-net , .

+4

Source: https://habr.com/ru/post/1611031/


All Articles