Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
huffman_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef HUFFMAN_P_H
6#define HUFFMAN_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists for the convenience
13// of other Qt classes. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
20
21class QByteArray;
22
23namespace HPack
24{
25
32
33class BitOStream;
34
35quint64 huffman_encoded_bit_length(QByteArrayView inputData);
36void huffman_encode_string(QByteArrayView inputData, BitOStream &outputStream);
37
38// PrefixTable:
39// Huffman codes with a small bit length
40// fit into a table (these are 'terminal' symbols),
41// codes with longer codes require additional
42// tables, so several symbols will have the same index
43// in a table - pointing into the next table.
44// Every table has an 'indexLength' - that's
45// how many bits can fit in table's indices +
46// 'prefixLength' - how many bits were addressed
47// by its 'parent' table(s).
48// All PrefixTables are kept in 'prefixTables' array.
49// PrefixTable itself does not have any entries,
50// it just holds table's prefix/index + 'offset' -
51// there table's data starts in an array of all
52// possible entries ('tableData').
53
55{
57 : prefixLength(),
59 offset()
60 {
61 }
62
63 PrefixTable(quint32 prefix, quint32 index)
66 offset()
67 {
68 }
69
71 {
72 // Number of entries table contains:
73 return 1 << indexLength;
74 }
75
79};
80
81// Table entry is either a terminal entry (thus probably the code found)
82// or points into another table ('nextTable' - index into
83// 'prefixTables' array). If it's a terminal, 'nextTable' index
84// refers to the same table.
85
99
100class BitIStream;
101
103{
104public:
105 enum class BitConstants
106 {
109 };
110
112
113 bool decodeStream(BitIStream &inputStream, QByteArray &outputBuffer);
114
115private:
116 quint32 addTable(quint32 prefixLength, quint32 indexLength);
117 PrefixTableEntry tableEntry(PrefixTable table, quint32 index);
118 void setTableEntry(PrefixTable table, quint32 index, PrefixTableEntry entry);
119
120 std::vector<PrefixTable> prefixTables;
121 std::vector<PrefixTableEntry> tableData;
122 quint32 minCodeLength;
123};
124
125bool huffman_decode_string(BitIStream &inputStream, QByteArray *outputBuffer);
126
127} // namespace HPack
128
129QT_END_NAMESPACE
130
131#endif
bool decodeStream(BitIStream &inputStream, QByteArray &outputBuffer)
Definition huffman.cpp:461
quint64 huffman_encoded_bit_length(QByteArrayView inputData)
Definition huffman.cpp:349
bool huffman_decode_string(BitIStream &inputStream, QByteArray *outputBuffer)
Definition huffman.cpp:531
void huffman_encode_string(QByteArrayView inputData, BitOStream &outputStream)
Definition huffman.cpp:358
quint32 byteValue
Definition huffman_p.h:28
quint32 bitLength
Definition huffman_p.h:30
quint32 huffmanCode
Definition huffman_p.h:29
PrefixTable(quint32 prefix, quint32 index)
Definition huffman_p.h:63
quint32 indexLength
Definition huffman_p.h:77
quint32 size() const
Definition huffman_p.h:70
quint32 prefixLength
Definition huffman_p.h:76