/// <summary> /// Serializes the <see cref="PeerSocketAddress"/> to a byte array. /// First, the ports (TCP, UDP) are serialized, then the address. /// </summary> /// <param name="me">The byte array to serialize to.</param> /// <param name="offset">The offset from where to start.</param> /// <returns>How many data has been written.</returns> public int ToByteArray(sbyte[] me, int offset) { var offset2 = offset; me[offset2++] = (sbyte)(TcpPort >> Utils.Utils.ByteBits); me[offset2++] = (sbyte)TcpPort; me[offset2++] = (sbyte)(UdpPort >> Utils.Utils.ByteBits); me[offset2++] = (sbyte)UdpPort; if (InetAddress.IsIPv4()) { Array.Copy(InetAddress.GetAddressBytes().ToSByteArray(), 0, me, offset2, Utils.Utils.IPv4Bytes); offset2 += Utils.Utils.IPv4Bytes; } else { Array.Copy(InetAddress.GetAddressBytes().ToSByteArray(), 0, me, offset2, Utils.Utils.IPv6Bytes); offset2 += Utils.Utils.IPv6Bytes; } return(offset2); }