示例#1
0
        public string PrintJson()
        {
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < _database.Length; i += DbRow.Size)
            {
                DbRow record = _database.Get(i);
                // Special casing Null so that it matches what JSON.NET does
                if (record.IsSimpleValue && record.JsonType != JsonType.Null)
                {
                    ReadOnlySpan <byte> value = _jsonData.Slice(record.Location, record.SizeOrLength);
                    sb.Append(Encoding.UTF8.GetString(value.ToArray())).Append(", ");
                }
            }
            return(sb.ToString());
        }
示例#2
0
        public void Remove(JsonObject obj)
        {
            ReadOnlySpan <byte> values = obj._jsonData;
            CustomDb            db     = obj._database;

            DbRow objRecord = db.Get();
            int   reduce    = objRecord.SizeOrLength;

            int idx = _database.Span.IndexOf(db.Span);

            int sliceVal = idx + db.Length;

            if (idx >= DbRow.Size)
            {
                reduce++;
                reduce++;
                idx -= DbRow.Size;
            }

            Span <byte> temp = _database.Slice(0, idx);

            for (int i = 0; i < temp.Length; i += DbRow.Size)
            {
                DbRow record = MemoryMarshal.Read <DbRow>(temp.Slice(i));
                if (!record.IsSimpleValue)
                {
                    DbRow myObj = _database.Get(i + record.SizeOrLength * DbRow.Size);
                    if (myObj.Location > objRecord.Location)
                    {
                        int   sizeOrlength = record.SizeOrLength - reduce;
                        int   numberOfRows = sizeOrlength == 0 ? 1 : sizeOrlength; //TODO: fix up for arrays
                        bool  hasChildren  = record.HasChildren;                   //TODO: Re-calculate HasChildren since it can become false
                        DbRow fixup        = new DbRow(record.JsonType, record.Location, hasChildren, sizeOrlength, numberOfRows);
                        MemoryMarshal.Write(temp.Slice(i), ref fixup);
                    }
                }
            }

            _database.Slice(sliceVal).CopyTo(_database.Slice(idx));
            _database.Span = _database.Slice(0, _database.Length - db.Length - DbRow.Size);
        }
        public void Remove(JsonObject obj)
        {
            ReadOnlySpan <byte> values = obj._jsonData;
            CustomDb            db     = obj._database;

            DbRow objRecord = db.Get();
            int   reduce    = objRecord.SizeOrLength;

            int idx = _database.Span.IndexOf(db.Span);

            int sliceVal = idx + db.Length;

            if (idx >= DbRow.Size)
            {
                reduce++;
                reduce++;
                idx -= DbRow.Size;
            }

            Span <byte> temp = _database.Slice(0, idx);

            for (int i = 0; i < temp.Length; i += DbRow.Size)
            {
                DbRow record = MemoryMarshal.Read <DbRow>(temp.Slice(i));
                if (!record.IsSimpleValue)
                {
                    DbRow myObj = _database.Get(i + record.SizeOrLength * DbRow.Size);
                    if (myObj.Location > objRecord.Location)
                    {
                        DbRow fixup = new DbRow(record.JsonType, record.Location, record.SizeOrLength - reduce);
                        MemoryMarshal.Write(temp.Slice(i), ref fixup);
                    }
                }
            }

            _database.Slice(sliceVal).CopyTo(_database.Slice(idx));
            _database.Span = _database.Slice(0, _database.Length - db.Length - DbRow.Size);
        }