예제 #1
0
        public unsafe void WriteString(LazyCompressedStringValue str)
        {
            var strBuffer = str.DecompressToTempBuffer();

            var size = str.UncompressedSize;

            EnsureBuffer(1);
            _buffer[_pos++] = Quote;
            var escapeSequencePos       = str.CompressedSize;
            var numberOfEscapeSequences = BlittableJsonReaderBase.ReadVariableSizeInt(str.Buffer, ref escapeSequencePos);

            while (numberOfEscapeSequences > 0)
            {
                numberOfEscapeSequences--;
                var bytesToSkip = BlittableJsonReaderBase.ReadVariableSizeInt(str.Buffer, ref escapeSequencePos);
                WriteRawString(strBuffer, bytesToSkip);
                strBuffer += bytesToSkip;
                size      -= bytesToSkip + 1 /*for the escaped char we skip*/;
                var b = *(strBuffer++);
                EnsureBuffer(2);
                _buffer[_pos++] = (byte)'\\';
                _buffer[_pos++] = GetEscapeCharacter(b);
            }
            // write remaining (or full string) to the buffer in one shot
            WriteRawString(strBuffer, size);

            EnsureBuffer(1);
            _buffer[_pos++] = Quote;
        }
        public bool Equals(LazyCompressedStringValue other)
        {
            if (other.UncompressedSize != UncompressedSize)
            {
                return(false);
            }

            if (other.CompressedSize == CompressedSize)
            {
                return(Memory.Compare(Buffer, other.Buffer, CompressedSize) == 0);
            }

            AllocatedMemoryData otherAllocated = null;
            AllocatedMemoryData allocated      = null;

            try
            {
                var otherTempBuffer = other.DecompressToTempBuffer(out otherAllocated);
                var tempBuffer      = DecompressToTempBuffer(out allocated);

                return(Memory.Compare(tempBuffer, otherTempBuffer, UncompressedSize) == 0);
            }
            finally
            {
                if (otherAllocated != null)
                {
                    other._context.ReturnMemory(otherAllocated);
                }

                if (allocated != null)
                {
                    _context.ReturnMemory(allocated);
                }
            }
        }
예제 #3
0
        public void WriteString(LazyCompressedStringValue str)
        {
            AllocatedMemoryData allocated;
            var strBuffer = str.DecompressToTempBuffer(out allocated);

            try
            {
                var size = str.UncompressedSize;

                EnsureBuffer(1);
                _buffer[_pos++] = Quote;
                var escapeSequencePos       = str.CompressedSize;
                var numberOfEscapeSequences = BlittableJsonReaderBase.ReadVariableSizeInt(str.Buffer, ref escapeSequencePos);
                while (numberOfEscapeSequences > 0)
                {
                    numberOfEscapeSequences--;
                    var bytesToSkip = BlittableJsonReaderBase.ReadVariableSizeInt(str.Buffer, ref escapeSequencePos);
                    WriteRawString(strBuffer, bytesToSkip);
                    strBuffer += bytesToSkip;
                    size      -= bytesToSkip + 1 /*for the escaped char we skip*/;
                    var b = *(strBuffer++);
                    EnsureBuffer(2);
                    _buffer[_pos++] = (byte)'\\';
                    _buffer[_pos++] = GetEscapeCharacter(b);
                }
                // write remaining (or full string) to the buffer in one shot
                WriteRawString(strBuffer, size);

                EnsureBuffer(1);
                _buffer[_pos++] = Quote;
            }
            finally
            {
                if (allocated != null) //precaution
                {
                    _context.ReturnMemory(allocated);
                }
            }
        }