private static unsafe bool CompareStringsWithEscapePositions(JsonOperationContext context, BlittableJsonReaderObject.PropertyDetails oldProp,
                                                                     BlittableJsonReaderObject.PropertyDetails newProp)
        {
            // this is called if the values are NOT equal, but we need to check if the oldProp was read from network and already resolved
            // the escape characters

            if (oldProp.Value is LazyStringValue lsv)
            {
                int pos = lsv.Size;
                int numOfEscapePositions = BlittableJsonReaderBase.ReadVariableSizeInt(lsv.Buffer, ref pos);
                if (numOfEscapePositions == 0)
                {
                    return(false);
                }

                using (var memoryStream = new MemoryStream())
                {
                    using (var textWriter = new BlittableJsonTextWriter(context, memoryStream))
                    {
                        textWriter.WriteString(lsv);
                        textWriter.Flush();
                    }
                    memoryStream.TryGetBuffer(out var bytes);
                    fixed(byte *pBuff = bytes.Array)
                    {
                        // need to ignore the quote marks
                        using var str = context.AllocateStringValue(null, pBuff + bytes.Offset + 1, (int)memoryStream.Length - 2);

                        return(newProp.Value.Equals(str));
                    }
                }
            }
            return(false);
        }
Example #2
0
        public TableValueReader(long id, byte *ptr, int size)
        {
            Id      = id;
            Pointer = ptr;
            Size    = size;

            if (size > ushort.MaxValue)
            {
                _elementSize = 4;
            }
            else if (size > byte.MaxValue)
            {
                _elementSize = 2;
            }
            else
            {
                _elementSize = 1;
            }

            byte offset;

            Count     = BlittableJsonReaderBase.ReadVariableSizeInt(ptr, 0, out offset);
            _dataPtr  = Pointer + offset;
            _dataSize = Size - offset;
        }
Example #3
0
        private void ReadEscapePositions(byte *buffer, int escapeSequencePos)
        {
            _state.EscapePositions.Clear();
            var numberOfEscapeSequences = BlittableJsonReaderBase.ReadVariableSizeInt(buffer, ref escapeSequencePos);

            while (numberOfEscapeSequences > 0)
            {
                numberOfEscapeSequences--;
                var bytesToSkip = BlittableJsonReaderBase.ReadVariableSizeInt(buffer, ref escapeSequencePos);
                _state.EscapePositions.Add(bytesToSkip);
            }
        }
Example #4
0
        private LazyStringValue SetTimestampTag()
        {
            if (_tagPointer.Pointer == null)
            {
                return(null);
            }

            var lazyStringLen = BlittableJsonReaderBase.ReadVariableSizeInt(_tagPointer.Pointer, 0, out var offset);

            _tag.Renew(null, _tagPointer.Pointer + offset, lazyStringLen);
            return(_tag);
        }
Example #5
0
        private static Document TableValueToDocument(JsonOperationContext context, TableValueReader tvr)
        {
            var result = new Document
            {
                StorageId = tvr.Id
            };
            int size;
            // See format of the lazy string key in the GetLowerKeySliceAndStorageKey method
            var  ptr = tvr.Read(3, out size);
            byte offset;

            size        = BlittableJsonReaderBase.ReadVariableSizeInt(ptr, 0, out offset);
            result.Key  = new LazyStringValue(null, ptr + offset, size, context);
            ptr         = tvr.Read(2, out size);
            result.Etag = IPAddress.NetworkToHostOrder(*(long *)ptr);
            result.Data = new BlittableJsonReaderObject(tvr.Read(4, out size), size, context);

            return(result);
        }