public byte *DecompressToTempBuffer()
        {
            var tempBuffer = _context.GetNativeTempBuffer(UncompressedSize);
            int uncompressedSize;

            if (UncompressedSize > 128)
            {
                uncompressedSize = LZ4.Decode64(Buffer,
                                                CompressedSize,
                                                tempBuffer,
                                                UncompressedSize,
                                                true);
            }
            else
            {
                uncompressedSize = SmallStringCompression.Instance.Decompress(Buffer,
                                                                              CompressedSize,
                                                                              tempBuffer,
                                                                              UncompressedSize);
            }

            if (uncompressedSize != UncompressedSize)
            {
                throw new FormatException("Wrong size detected on decompression");
            }

            return(tempBuffer);
        }
Exemple #2
0
        public int CompareTo(string other)
        {
            var sizeInBytes = Encoding.UTF8.GetMaxByteCount(other.Length);
            var tmp         = Context.GetNativeTempBuffer(sizeInBytes, out sizeInBytes);

            fixed(char *pOther = other)
            {
                var tmpSize = Context.Encoding.GetBytes(pOther, other.Length, tmp, sizeInBytes);

                return(Compare(tmp, tmpSize));
            }
        }
Exemple #3
0
        public unsafe int WriteValue(string str, out BlittableJsonToken token, UsageMode mode = UsageMode.None)
        {
            if (_intBuffer == null)
            {
                _intBuffer = new List <int>();
            }
            int size = Encoding.UTF8.GetMaxByteCount(str.Length);

            FillBufferWithEscapePositions(str, _intBuffer);
            size += JsonParserState.GetEscapePositionsSize(_intBuffer);
            var buffer = _context.GetNativeTempBuffer(size);

            fixed(char *pChars = str)
            {
                var stringSize = Utf8Encoding.GetBytes(pChars, str.Length, buffer, size);

                return(WriteValue(buffer, stringSize, _intBuffer, out token, mode, null));
            }
        }