private static IpV6FlowIdentificationSubOption CreateOption(IpV6FlowIdentificationSubOptionType optionType, DataSegment data) { IpV6FlowIdentificationSubOption prototype; if (!_prototypes.TryGetValue(optionType, out prototype)) { return(new IpV6FlowIdentificationSubOptionUnknown(optionType, data)); } return(prototype.CreateInstance(data)); }
internal static Tuple <IList <IpV6FlowIdentificationSubOption>, bool> Read(DataSegment data) { int offset = 0; List <IpV6FlowIdentificationSubOption> options = new List <IpV6FlowIdentificationSubOption>(); bool isValid = true; while (offset < data.Length) { IpV6FlowIdentificationSubOptionType optionType = (IpV6FlowIdentificationSubOptionType)data[offset++]; if (optionType == IpV6FlowIdentificationSubOptionType.Pad1) { options.Add(new IpV6FlowIdentificationSubOptionPad1()); continue; } if (offset >= data.Length) { isValid = false; break; } byte optionDataLength = data[offset++]; if (offset + optionDataLength > data.Length) { isValid = false; break; } IpV6FlowIdentificationSubOption option = CreateOption(optionType, data.Subsegment(ref offset, optionDataLength)); if (option == null) { isValid = false; break; } options.Add(option); } return(new Tuple <IList <IpV6FlowIdentificationSubOption>, bool>(options, isValid)); }
public static IpV6FlowIdentificationSubOption NextIpV6FlowIdentificationSubOption(this Random random) { IpV6FlowIdentificationSubOptionType optionType = random.NextEnum <IpV6FlowIdentificationSubOptionType>(); switch (optionType) { case IpV6FlowIdentificationSubOptionType.Pad1: return(new IpV6FlowIdentificationSubOptionPad1()); case IpV6FlowIdentificationSubOptionType.PadN: return(new IpV6FlowIdentificationSubOptionPadN(random.NextInt(0, 10))); case IpV6FlowIdentificationSubOptionType.BindingReference: return(new IpV6FlowIdentificationSubOptionBindingReference(((Func <ushort>)(random.NextUShort)).GenerateArray(random.NextInt(0, 10)))); case IpV6FlowIdentificationSubOptionType.TrafficSelector: return(new IpV6FlowIdentificationSubOptionTrafficSelector(random.NextEnum <IpV6FlowIdentificationTrafficSelectorFormat>(), random.NextDataSegment(random.NextInt(0, 40)))); default: throw new InvalidOperationException(string.Format("Invalid optionType value {0}", optionType)); } }
public IpV6FlowIdentificationSubOptionTypeRegistrationAttribute(IpV6FlowIdentificationSubOptionType optionType) { OptionType = optionType; }
internal IpV6FlowIdentificationSubOptionComplex(IpV6FlowIdentificationSubOptionType type) : base(type) { }
internal IpV6FlowIdentificationSubOptionSimple(IpV6FlowIdentificationSubOptionType type) : base(type) { }
/// <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 IpV6FlowIdentificationSubOptionUnknown(IpV6FlowIdentificationSubOptionType type, DataSegment data) : base(type) { Data = data; }
internal IpV6FlowIdentificationSubOption(IpV6FlowIdentificationSubOptionType type) { OptionType = type; }