namespace OSMImporter { public class Node : Coordinates { private readonly HashSet _connections = new HashSet(); public Node(float lat, float lon) : base(lat, lon) { } public void AddConnection(Connection connection) { this._connections.Add(connection); } public Connection[] GetConnections() { return this._connections.ToArray(); } /* * Returns byte array in order: * Value 1: Latitude (4bytes) * Value 2: Longitude (4bytes) * Value 3: Connections-Count (1 byte) * Value x: Connection */ public byte[] ToByte() { long countBytes = 0; float[] coords = { this.lat, this.lon }; countBytes += sizeof(float) * 2; HashSet byteConnections = new(); foreach (Connection connection in this._connections) { byte[] connectionBytes = connection.ToByte(); byteConnections.Add(connectionBytes); countBytes += connectionBytes.Length; } byte connectionsAmount = Convert.ToByte(byteConnections.Count); countBytes++; int offset = 0; byte[] ret = new byte[countBytes]; Buffer.BlockCopy(coords, 0, ret, offset, sizeof(float) * 2); offset += sizeof(float) * 2; Buffer.SetByte(ret, offset, connectionsAmount); offset++; foreach (byte[] connection in byteConnections) { Buffer.BlockCopy(connection, 0, ret, offset, connection.Length); offset += connection.Length; } return ret; } } }