BitSharper.PeerAddress.BitcoinSerializeToStream C# (CSharp) Method

BitcoinSerializeToStream() public method

public BitcoinSerializeToStream ( Stream stream ) : void
stream Stream
return void
        public override void BitcoinSerializeToStream(Stream stream)
        {
            if (ProtocolVersion >= 31402)
            {
                var secs = UnixTime.ToUnixTime(DateTime.UtcNow);
                Utils.Uint32ToByteStreamLe((uint) secs, stream);
            }
            Utils.Uint64ToByteStreamLe(_services, stream); // nServices.
            // Java does not provide any utility to map an IPv4 address into IPv6 space, so we have to do it by hand.
            var ipBytes = Addr.GetAddressBytes();
            if (ipBytes.Length == 4)
            {
                var v6Addr = new byte[16];
                Array.Copy(ipBytes, 0, v6Addr, 12, 4);
                v6Addr[10] = 0xFF;
                v6Addr[11] = 0xFF;
                ipBytes = v6Addr;
            }
            stream.Write(ipBytes);
            // And write out the port. Unlike the rest of the protocol, address and port is in big endian byte order.
            stream.Write((byte) (Port >> 8));
            stream.Write((byte) Port);
        }