Ejemplo n.º 1
0
        internal static Node FromCompactNode(ReadOnlySpan <byte> buffer)
        {
            if (buffer.Length != 26)
            {
                throw new ArgumentException("buffer must be exactly 26 bytes long", nameof(buffer));
            }

            byte[] id = new byte[20];
            buffer.Slice(0, 20).CopyTo(id);
            var address = new IPAddress(BinaryPrimitives.ReadUInt32LittleEndian(buffer.Slice(20, 4)));
            int port    = BinaryPrimitives.ReadUInt16BigEndian(buffer.Slice(24, 2));

            return(new Node(NodeId.FromMemory(id), new IPEndPoint(address, port)));
        }