namespace OsmXmlToRegionConverter; public class Node { public ulong id { get; } public Coordinates coordinates { get; } public HashSet edges { get; } public Node(ulong id, float latitude, float longitude) { this.id = id; coordinates = new Coordinates(latitude, longitude); edges = new HashSet(); } public Node(ulong id, Coordinates coordinates) { this.id = id; this.coordinates = coordinates; edges = new HashSet(); } public void AddEdge(Edge edge) { edges.Add(edge); } public const int ByteSizeEmpty = sizeof(int) + sizeof(ulong) + Coordinates.ByteSize; public static Node FromBytes(byte[] bytes) { using (MemoryStream m = new MemoryStream(bytes)) { using (BinaryReader r = new BinaryReader(m)) { int edgeCount = r.ReadInt32(); ulong id = r.ReadUInt64(); byte[] coordinateBytes = r.ReadBytes(sizeof(float) * 2); Coordinates coordinates = Coordinates.FromBytes(coordinateBytes); Node ret = new Node(id, coordinates); for (int i = 0; i < edgeCount; i++) ret.AddEdge(Edge.FromBytes(r.ReadBytes(Edge.ByteSize))); return ret; } } } }