public override List <IPv4Prefix> Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            if (reader.TokenType != JsonTokenType.StartArray)
            {
                throw new FormatException();
            }
            var value = new List <IPv4Prefix>();

            while (reader.Read())
            {
                if (reader.TokenType == JsonTokenType.String)
                {
                    value.Add(IPv4.ParsePrefix(reader.GetString()));
                }
                else if (reader.TokenType == JsonTokenType.EndArray)
                {
                    return(value);
                }
                else
                {
                    throw new FormatException();
                }
            }

            throw new FormatException();
        }
Beispiel #2
0
        public void ParsePrefix()
        {
            var testPrefix = settings.Value.TestPrefix;
            var testCount  = settings.Value.TestCount;

            IPv4Prefix x = IPv4Prefix.Parse(testPrefix);

            Console.WriteLine($"Test: {IPv4.ConvertToBitString(x.IP)} {x.ToString()} [ParsePrefix prefix:{testPrefix}]");

            var sw = Stopwatch.StartNew();

            for (int i = 0; i < testCount; i++)
            {
                _ = IPv4.ParsePrefix(testPrefix);
            }
            Console.WriteLine($" - {sw.ElapsedMilliseconds} ms");
        }