Пример #1
0
            private int ReadTimeStamp(BitsBuffer bitsBuffer)
            {
                if (_bitsPosisition == 0)
                {
                    _previousTimeStamp      = (int)bitsBuffer.ReadValue(ref _bitsPosisition, BitsForFirstTimestamp);
                    _previousTimeStampDelta = DefaultDelta;
                    return(_previousTimeStamp);
                }

                var type = bitsBuffer.FindTheFirstZeroBit(ref _bitsPosisition, TimestampEncodingDetails.MaxControlBitLength);

                if (type > 0)
                {
                    var     index        = type - 1;
                    ref var encoding     = ref TimestampEncodingDetails.Encodings[index];
                    long    decodedValue = (long)bitsBuffer.ReadValue(ref _bitsPosisition, encoding.BitsForValue);
                    // [0, 255] becomes [-128, 127]
                    decodedValue -= encoding.MaxValueForEncoding;
                    if (decodedValue >= 0)
                    {
                        // [-128, 127] becomes [-128, 128] without the zero in the middle
                        decodedValue++;
                    }
                    _previousTimeStampDelta += (int)decodedValue;
                }
Пример #2
0
            private void ReadValues(Span <StatefulTimeStampValue> values, ref BitsBuffer bitsBuffer)
            {
                for (int i = 0; i < values.Length; i++)
                {
                    var nonZero = bitsBuffer.ReadValue(ref _bitsPosisition, 1);
                    if (nonZero == 0)
                    {
                        continue; // no change since last time
                    }
                    var  usePreviousBlockInfo = bitsBuffer.ReadValue(ref _bitsPosisition, 1);
                    long xorValue;

                    if (usePreviousBlockInfo == 1)
                    {
                        xorValue   = (long)bitsBuffer.ReadValue(ref _bitsPosisition, 64 - values[i].LeadingZeroes - values[i].TrailingZeroes);
                        xorValue <<= values[i].TrailingZeroes;
                    }
                    else
                    {
                        int leadingZeros  = (int)bitsBuffer.ReadValue(ref _bitsPosisition, LeadingZerosLengthBits);
                        int blockSize     = (int)bitsBuffer.ReadValue(ref _bitsPosisition, BlockSizeLengthBits) + BlockSizeAdjustment;
                        int trailingZeros = 64 - blockSize - leadingZeros;

                        xorValue   = (long)bitsBuffer.ReadValue(ref _bitsPosisition, blockSize);
                        xorValue <<= trailingZeros;

                        values[i].TrailingZeroes = (byte)trailingZeros;
                        values[i].LeadingZeroes  = (byte)leadingZeros;
                    }

                    values[i].LongValue = values[i].LongValue ^ xorValue;
                }
            }
Пример #3
0
            public bool TryGetPrevious(out Span <byte> tag, out int previousIndex)
            {
                if (_previousTagPos == 0)
                {
                    tag           = default;
                    previousIndex = default;
                    return(false);
                }
                previousIndex = _previousTagPos;
                var tagLen = _bitsBuffer.Buffer[_previousTagPos++];

                tag = new Span <byte>(_bitsBuffer.Buffer + _previousTagPos, tagLen);
                var offset = (_previousTagPos + tag.Length) * 8;

                _previousTagPos = (int)_bitsBuffer.ReadValue(ref offset, BitsForTagLen);
                return(true);
            }
Пример #4
0
        internal bool AddBits(BitsBuffer tempBitsBuffer)
        {
            if (HasAdditionalBits(tempBitsBuffer.NumberOfBits) == false)
            {
                return(false);
            }

            int read = 0;

            while (read < tempBitsBuffer.NumberOfBits)
            {
                var toRead = Math.Min(64, tempBitsBuffer.NumberOfBits - read);
                var result = tempBitsBuffer.ReadValue(ref read, toRead);
                AddValue(result, toRead);
            }

            return(true);
        }