Messagelib

riceencodingdecoder.h
1 /*
2  SPDX-FileCopyrightText: 2016-2023 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "updatedatabaseinfo.h"
10 #include "webengineviewer_private_export.h"
11 #include <QVector>
12 namespace WebEngineViewer
13 {
14 // https://developers.google.com/safe-browsing/v4/compression
15 class RiceDecoder
16 {
17 public:
18  RiceDecoder(int riceParameter, int numberEntries, const QByteArray &encodingData);
19  ~RiceDecoder();
20 
21  Q_REQUIRED_RESULT bool hasOtherEntries() const;
22  Q_REQUIRED_RESULT bool nextValue(uint32_t *value);
23  Q_REQUIRED_RESULT bool nextBits(unsigned int num_requested_bits, uint32_t *x);
24  Q_REQUIRED_RESULT uint32_t bitsFromCurrentWord(unsigned int num_requested_bits);
25  Q_REQUIRED_RESULT bool nextWord(uint32_t *word);
26 
27 private:
28  QByteArray mEncodingData;
29  int mRiceParameter;
30  int mNumberEntries;
31 
32  // Represents how many total bytes have we read from |data_| into
33  // |mCurrentWord|.
34  int mDataByteIndex;
35 
36  // Represents the number of bits that we have read from |mCurrentWord|. When
37  // this becomes 32, which is the size of |mCurrentWord|, a new
38  // |mCurrentWord| needs to be read from |data_|.
39  unsigned int mCurrentWordBitIndex;
40 
41  // The 32-bit value read from |data_|. All bit reading operations operate on
42  // |mCurrentWord|.
43  uint32_t mCurrentWord;
44 };
45 
46 class WEBENGINEVIEWER_TESTS_EXPORT RiceEncodingDecoder
47 {
48 public:
49  RiceEncodingDecoder();
50  ~RiceEncodingDecoder();
51 
52  static QVector<quint32> decodeRiceIndiceDelta(const WebEngineViewer::RiceDeltaEncoding &riceDeltaEncoding);
53  static QVector<quint32> decodeRiceHashesDelta(const WebEngineViewer::RiceDeltaEncoding &riceDeltaEncoding);
54 };
55 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Mar 24 2023 04:08:32 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.