Пример #1
0
            public static PeerAddressIp Decode(IByteReader stream)
            {
                PeerAddressIp decodedPeerAddressIp = new PeerAddressIp();

                decodedPeerAddressIp.Discriminant = IPAddrType.Decode(stream);
                switch (decodedPeerAddressIp.Discriminant.InnerValue)
                {
                case IPAddrType.IPAddrTypeEnum.IPv4:
                    int ipv4size = 4;
                    decodedPeerAddressIp.Ipv4 = XdrEncoding.ReadFixOpaque(stream, (uint)ipv4size);
                    break;

                case IPAddrType.IPAddrTypeEnum.IPv6:
                    int ipv6size = 16;
                    decodedPeerAddressIp.Ipv6 = XdrEncoding.ReadFixOpaque(stream, (uint)ipv6size);
                    break;
                }
                return(decodedPeerAddressIp);
            }
Пример #2
0
            public static PeerAddressIp Decode(XdrDataInputStream stream)
            {
                var decodedPeerAddressIp = new PeerAddressIp();
                var discriminant         = IPAddrType.Decode(stream);

                decodedPeerAddressIp.Discriminant = discriminant;
                switch (decodedPeerAddressIp.Discriminant.InnerValue)
                {
                case IPAddrType.IPAddrTypeEnum.IPv4:
                    var ipv4size = 4;
                    decodedPeerAddressIp.Ipv4 = new byte[ipv4size];
                    stream.Read(decodedPeerAddressIp.Ipv4, 0, ipv4size);
                    break;

                case IPAddrType.IPAddrTypeEnum.IPv6:
                    var ipv6size = 16;
                    decodedPeerAddressIp.Ipv6 = new byte[ipv6size];
                    stream.Read(decodedPeerAddressIp.Ipv6, 0, ipv6size);
                    break;
                }
                return(decodedPeerAddressIp);
            }