9#include "riceencodingdecoder.h"
10#include "webengineviewer_debug.h"
15#include <netinet/in.h>
20const int kBitsPerByte = 8;
21const unsigned int kMaxBitIndex = kBitsPerByte *
sizeof(uint32_t);
24using namespace WebEngineViewer;
25RiceEncodingDecoder::RiceEncodingDecoder() =
default;
27RiceEncodingDecoder::~RiceEncodingDecoder() =
default;
29QList<quint32> RiceEncodingDecoder::decodeRiceIndiceDelta(
const RiceDeltaEncoding &riceDeltaEncoding)
33 if (riceDeltaEncoding.firstValue.
isEmpty()) {
36 quint64 firstValue = riceDeltaEncoding.firstValue.
toInt(&ok);
38 qCWarning(WEBENGINEVIEWER_LOG) <<
"First value is not a int value " << riceDeltaEncoding.firstValue;
43 if (riceDeltaEncoding.numberEntries == 0) {
47 RiceDecoder decoder(riceDeltaEncoding.riceParameter, riceDeltaEncoding.numberEntries, riceDeltaEncoding.encodingData);
48 int lastValue(firstValue);
49 while (decoder.hasOtherEntries()) {
51 bool result = decoder.nextValue(&offset);
58 if (!last_value.IsValid()) {
68QList<quint32> RiceEncodingDecoder::decodeRiceHashesDelta(
const RiceDeltaEncoding &riceDeltaEncoding)
72 quint64 firstValue = riceDeltaEncoding.firstValue.
toInt(&ok);
74 qCWarning(WEBENGINEVIEWER_LOG) <<
"First value is not a int value " << riceDeltaEncoding.firstValue;
79 RiceDecoder decoder(riceDeltaEncoding.riceParameter, riceDeltaEncoding.numberEntries, riceDeltaEncoding.encodingData);
80 int lastValue(firstValue);
81 list << htonl(lastValue);
83 while (decoder.hasOtherEntries()) {
85 bool result = decoder.nextValue(&offset);
98 list << htonl(lastValue);
110 for (
int i = 0; i < listCount; ++i) {
111 newList << ntohl(
list.
at(i));
116RiceDecoder::RiceDecoder(
int riceParameter,
int numberEntries,
const QByteArray &encodingData)
117 : mEncodingData(encodingData)
118 , mRiceParameter(riceParameter)
119 , mNumberEntries(numberEntries)
123 mCurrentWordBitIndex = kMaxBitIndex;
126RiceDecoder::~RiceDecoder() =
default;
128bool RiceDecoder::hasOtherEntries()
const
130 return mNumberEntries > 0;
133bool RiceDecoder::nextValue(uint32_t *value)
135 if (!hasOtherEntries()) {
142 result = nextBits(1, &bit);
149 result = nextBits(mRiceParameter, &r);
154 *value = (q << mRiceParameter) + r;
159bool RiceDecoder::nextBits(
unsigned int numRequestedBits, uint32_t *x)
161 if (numRequestedBits > kMaxBitIndex) {
164 if (mCurrentWordBitIndex == kMaxBitIndex) {
165 bool result = nextWord(&mCurrentWord);
170 unsigned int num_bits_left_in_current_word = kMaxBitIndex - mCurrentWordBitIndex;
171 if (num_bits_left_in_current_word >= numRequestedBits) {
173 *x = bitsFromCurrentWord(numRequestedBits);
179 uint32_t lower = bitsFromCurrentWord(num_bits_left_in_current_word);
181 unsigned int num_bits_from_next_word = numRequestedBits - num_bits_left_in_current_word;
183 bool result = nextBits(num_bits_from_next_word, &upper);
187 *x = (upper << num_bits_left_in_current_word) | lower;
192bool RiceDecoder::nextWord(uint32_t *word)
194 if (mDataByteIndex >= mEncodingData.
size()) {
198 const size_t mask = 0xFF;
199 *word = (mEncodingData[mDataByteIndex] & mask);
201 mCurrentWordBitIndex = 0;
203 if (mDataByteIndex < mEncodingData.
size()) {
204 *word |= ((mEncodingData[mDataByteIndex] & mask) << 8);
207 if (mDataByteIndex < mEncodingData.
size()) {
208 *word |= ((mEncodingData[mDataByteIndex] & mask) << 16);
211 if (mDataByteIndex < mEncodingData.
size()) {
212 *word |= ((mEncodingData[mDataByteIndex] & mask) << 24);
220uint32_t RiceDecoder::bitsFromCurrentWord(
unsigned int numRequestedBits)
222 uint32_t mask = 0xFFFFFFFF >> (kMaxBitIndex - numRequestedBits);
223 uint32_t x = mCurrentWord & mask;
224 mCurrentWord = mCurrentWord >> numRequestedBits;
225 mCurrentWordBitIndex += numRequestedBits;
KIOCORE_EXPORT QStringList list(const QString &fileClass)
bool isEmpty() const const
qsizetype size() const const
int toInt(bool *ok, int base) const const
const_reference at(qsizetype i) const const
qsizetype count() const const
void reserve(qsizetype size)