internal static Tuple <IList <IpV6AccessNetworkIdentifierSubOption>, bool> Read(DataSegment data)
        {
            int offset = 0;
            List <IpV6AccessNetworkIdentifierSubOption> options = new List <IpV6AccessNetworkIdentifierSubOption>();
            bool isValid = true;

            while (offset < data.Length)
            {
                IpV6AccessNetworkIdentifierSubOptionType optionType = (IpV6AccessNetworkIdentifierSubOptionType)data[offset++];
                if (offset >= data.Length)
                {
                    isValid = false;
                    break;
                }

                byte optionDataLength = data[offset++];
                if (offset + optionDataLength > data.Length)
                {
                    isValid = false;
                    break;
                }

                IpV6AccessNetworkIdentifierSubOption option = CreateOption(optionType, data.Subsegment(ref offset, optionDataLength));
                if (option == null)
                {
                    isValid = false;
                    break;
                }

                options.Add(option);
            }

            return(new Tuple <IList <IpV6AccessNetworkIdentifierSubOption>, bool>(options, isValid));
        }
        private static IpV6AccessNetworkIdentifierSubOption CreateOption(IpV6AccessNetworkIdentifierSubOptionType optionType, DataSegment data)
        {
            IpV6AccessNetworkIdentifierSubOption prototype;

            if (!_prototypes.TryGetValue(optionType, out prototype))
            {
                return(new IpV6AccessNetworkIdentifierSubOptionUnknown(optionType, data));
            }
            return(prototype.CreateInstance(data));
        }
        public static IpV6AccessNetworkIdentifierSubOption NextIpV6AccessNetworkIdentifierSubOption(this Random random)
        {
            IpV6AccessNetworkIdentifierSubOptionType optionType = random.NextEnum(IpV6AccessNetworkIdentifierSubOptionType.None);

            switch (optionType)
            {
            case IpV6AccessNetworkIdentifierSubOptionType.NetworkIdentifier:
                return(new IpV6AccessNetworkIdentifierSubOptionNetworkIdentifier(random.NextBool(), random.NextDataSegment(random.NextInt(0, 100)),
                                                                                 random.NextDataSegment(random.NextInt(0, 100))));

            case IpV6AccessNetworkIdentifierSubOptionType.GeoLocation:
                double latitude  = random.NextDouble() * 180 - 90;
                double longitude = random.NextDouble() * 360 - 180;
                return(IpV6AccessNetworkIdentifierSubOptionGeoLocation.CreateFromRealValues(latitude, longitude));

            case IpV6AccessNetworkIdentifierSubOptionType.OperatorIdentifier:
                return(new IpV6AccessNetworkIdentifierSubOptionOperatorIdentifier(random.NextEnum <IpV6AccessNetworkIdentifierOperatorIdentifierType>(),
                                                                                  random.NextDataSegment(random.NextInt(0, 100))));

            default:
                throw new InvalidOperationException(string.Format("Invalid optionType value {0}", optionType));
            }
        }
示例#4
0
 /// <summary>
 /// Creates an instance from type and data.
 /// </summary>
 /// <param name="type">The type of the option.</param>
 /// <param name="data">The data of the option.</param>
 public IpV6AccessNetworkIdentifierSubOptionUnknown(IpV6AccessNetworkIdentifierSubOptionType type, DataSegment data)
     : base(type)
 {
     Data = data;
 }
 public IpV6AccessNetworkIdentifierSubOptionTypeRegistrationAttribute(IpV6AccessNetworkIdentifierSubOptionType optionType)
 {
     OptionType = optionType;
 }
 /// <summary>
 /// Creates an instance from type and data.
 /// </summary>
 /// <param name="type">The type of the option.</param>
 /// <param name="data">The data of the option.</param>
 public IpV6AccessNetworkIdentifierSubOptionUnknown(IpV6AccessNetworkIdentifierSubOptionType type, DataSegment data)
     : base(type)
 {
     Data = data;
 }
示例#7
0
 internal IpV6AccessNetworkIdentifierSubOption(IpV6AccessNetworkIdentifierSubOptionType type)
 {
     OptionType = type;
 }
 public IpV6AccessNetworkIdentifierSubOptionTypeRegistrationAttribute(IpV6AccessNetworkIdentifierSubOptionType optionType)
 {
     OptionType = optionType;
 }