Пример #1
0
        //[Fact]
        public void ValidateMinifier()
        {
            string json = @"{
                              ""Egor"":  ""Bogatov"" 
                            }
                            ";

            string minifiedJson = SimdJson.MinifyJson(json);

            Assert.Equal(@"{""Egor"":""Bogatov""}", minifiedJson);
            // TODO: more tests
        }
Пример #2
0
        static void Main(string[] args)
        {
            ReadOnlySpan <byte> beforeData = LoadEmbeddedFile("MinifyJson.sample.json");

            string beforeString = Encoding.UTF8.GetString(beforeData);

            Console.WriteLine($"Before:\n{beforeString}\nLength={beforeString.Length}");

            string afterString = SimdJson.MinifyJson(beforeString); // there is also Span API

            Console.WriteLine($"\n\nAfter:\n{afterString}.\nLength={afterString.Length}");
        }
Пример #3
0
        public unsafe string SimdJson_Validation(byte[] jsonData, string fileName, string fileSize)
        {
            string json = Encoding.UTF8.GetString(jsonData);

            // Validate json first
            // this step is not required for minification, it's here because JSON.NET also does validation
            fixed(byte *dataPtr = jsonData)
            {
                using (var doc = SimdJson.ParseJson(dataPtr, jsonData.Length))
                    if (!doc.IsValid)
                    {
                        throw new InvalidOperationException("Json is invalid");
                    }
            }

            return(SimdJson.MinifyJson(json));
        }
Пример #4
0
        public unsafe void ValidateMinimizedJson()
        {
            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);
                Span <byte>         output   = new byte[fileData.Length];
                SimdJson.MinifyJson(fileData, output, out int bytesWritten);
                output = output.Slice(0, bytesWritten);

                fixed(byte *outPtr = output)
                using (ParsedJson doc = SimdJson.ParseJson(outPtr, (ulong)output.Length))
                    Assert.True(doc.IsValid);
            }
        }
Пример #5
0
        public unsafe void ValidateMinimizedJson()
        {
            string currentDir  = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            string testDataDir = Path.Combine(currentDir, @"../../../../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);
                Span <byte>         output   = new byte[fileData.Length];
                SimdJson.MinifyJson(fileData, output, out int bytesWritten);
                output = output.Slice(0, bytesWritten);

                fixed(byte *outPtr = output)
                using (ParsedJson doc = SimdJson.ParseJson(outPtr, output.Length))
                    Assert.True(doc.IsValid);
            }
        }
Пример #6
0
        public string SimdJson_NoValidation(byte[] jsonData, string fileName, string fileSize)
        {
            string json = Encoding.UTF8.GetString(jsonData);

            return(SimdJson.MinifyJson(json));
        }