Exemplo n.º 1
0
        static unsafe void Main(string[] args)
        {
            string helloWorldJson     = "{ \"answer\": 42, \"name\": \"Egor\" }";
            ReadOnlySpan <byte> bytes = Encoding.UTF8.GetBytes(helloWorldJson);

            // SimdJson is UTF8 only

            using (ParsedJson doc = SimdJson.build_parsed_json(bytes))
            {
                Console.WriteLine("Is json valid:" + doc.isValid());

                // open iterator:
                using (iterator iterator = new iterator(&doc))
                {
                    while (iterator.move_forward())
                    {
                        switch (iterator.GetTokenType())
                        {
                        case JsonTokenType.Number:
                            Console.WriteLine("integer: " + iterator.get_integer());
                            break;

                        case JsonTokenType.String:
                            Console.WriteLine("string: " + iterator.GetUtf16String());
                            break;
                        }
                    }
                }
            }
        }
        public void ValidateAllFiles()
        {
            string currentDir  = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string testDataDir = Path.Combine(currentDir, @"../../../../../external/simdjson/jsonexamples");

            string[] files = Directory.GetFiles(testDataDir, "*.json", SearchOption.AllDirectories);
            // 20 files, ~15Mb of JSON
            Assert.NotEmpty(files);
            foreach (string file in files)
            {
                ReadOnlySpan <byte> fileData = File.ReadAllBytes(file);
                using (ParsedJson doc = SimdJson.build_parsed_json(fileData))
                {
                    Assert.True(doc.isValid());
                }
            }
        }
Exemplo n.º 3
0
        public unsafe ulong SimdJsonSharpApi(byte[] data, string fileName, string fileSize)
        {
            ulong numbersCount = 0;

            using (ParsedJson doc = SimdJson.build_parsed_json(data))
            {
                using (var iterator = new iterator(&doc))
                {
                    while (iterator.move_forward())
                    {
                        if (iterator.is_integer() || iterator.is_double())
                        {
                            numbersCount++;
                        }
                    }
                }
            }

            return(numbersCount);
        }