示例#1
0
        public double ReadNextValue()
        {
            var nonZeroValue = _buffer.ReadValue(1);

            if (nonZeroValue == 0)
            {
                return(BitConverter.Int64BitsToDouble(_previousValue));
            }

            var  usePreviousBlockInfo = _buffer.ReadValue(1);
            long xorValue;

            if (usePreviousBlockInfo == 1)
            {
                xorValue   = ( long )_buffer.ReadValue(_previousBlockInfo.BlockSize);
                xorValue <<= _previousBlockInfo.TrailingZeros;
            }
            else
            {
                int leadingZeros  = (int)_buffer.ReadValue(Constants.LeadingZerosLengthBits);
                int blockSize     = (int)_buffer.ReadValue(Constants.BlockSizeLengthBits) + Constants.BlockSizeAdjustment;
                int trailingZeros = 64 - blockSize - leadingZeros;
                xorValue   = ( long )_buffer.ReadValue(blockSize);
                xorValue <<= trailingZeros;

                _previousBlockInfo = new BlockInfo(leadingZeros, trailingZeros);
            }

            long value = xorValue ^ _previousValue;

            _previousValue = value;

            return(BitConverter.Int64BitsToDouble(value));
        }
示例#2
0
        public DateTime ReadNextDateTime()
        {
            if (_hasReadFirstValue == false)
            {
                var unixTime = (int)_buffer.ReadValue(Constants.BitsForFirstTimestamp);

                _previousTimestamp      = unixTime;
                _previousTimestampDelta = Constants.DefaultDelta;
                _hasReadFirstValue      = true;

                return(FromUnixTime(unixTime));
            }

            var type = _buffer.FindTheFirstZeroBit(TimestampEncodingDetails.MaxControlBitLength);

            if (type > 0)
            {
                // Delta of delta is non zero.  Calculate the new delta. "index" will
                // be used to find the right encoding.
                int index    = type - 1;
                var encoding = TimestampEncodingDetails.Encodings[index];

                long decodedValue = (long)_buffer.ReadValue(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;
            }

            _previousTimestamp += _previousTimestampDelta;
            return(FromUnixTime(_previousTimestamp));
        }