MySQL 8.4.2
Source Code Documentation
dict0sdi-decompress.h
Go to the documentation of this file.
1/*****************************************************************************
2
3Copyright (c) 2017, 2024, Oracle and/or its affiliates.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License, version 2.0, as published by the
7Free Software Foundation.
8
9This program is designed to work with certain software (including
10but not limited to OpenSSL) that is licensed under separate terms,
11as designated in a particular file or component or in included license
12documentation. The authors of MySQL hereby grant you an additional
13permission to link the program and your derivative works with the
14separately licensed software that they have either included with
15the program or referenced in the documentation.
16
17This program is distributed in the hope that it will be useful, but WITHOUT
18ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19FOR A PARTICULAR PURPOSE. See the GNU General Public License, version 2.0,
20for more details.
21
22You should have received a copy of the GNU General Public License along with
23this program; if not, write to the Free Software Foundation, Inc.,
2451 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
26*****************************************************************************/
27
28#ifndef DICT_SDI_DECOMPRESS_H
29#define DICT_SDI_DECOMPRESS_H
30
31#include <zlib.h>
32
33/** Decompress SDI record */
35 public:
36 Sdi_Decompressor(byte *uncomp_sdi, uint32_t uncomp_len, byte *comp_sdi,
37 uint32_t comp_len)
38 : m_uncomp_sdi(uncomp_sdi),
39 m_uncomp_len(uncomp_len),
40 m_comp_sdi(comp_sdi),
41 m_comp_len(comp_len) {
42 ut_ad(m_uncomp_sdi != nullptr);
43 ut_ad(m_comp_sdi != nullptr);
44 }
45
46 ~Sdi_Decompressor() = default;
47
48 /** Decompress the SDI and store in the buffer passed. */
49 inline void decompress() {
50 int ret;
51 uLongf dest_len = m_uncomp_len;
52 ret = uncompress(m_uncomp_sdi, &dest_len, m_comp_sdi, m_comp_len);
53
54 if (ret != Z_OK) {
55#ifdef UNIV_NO_ERR_MSGS
56 ib::error()
57#else
58 ib::error(ER_IB_ERR_ZLIB_UNCOMPRESS_FAILED)
59#endif
60 << "ZLIB uncompress() failed:"
61 << " compressed len: " << m_comp_len
62 << ", original_len: " << m_uncomp_len;
63
64 switch (ret) {
65 case Z_BUF_ERROR:
66#ifdef UNIV_NO_ERR_MSGS
68#else
69 ib::fatal(UT_LOCATION_HERE, ER_IB_ERR_ZLIB_BUF_ERROR)
70#endif
71
72 << "retval = Z_BUF_ERROR";
73 break;
74
75 case Z_MEM_ERROR:
76#ifdef UNIV_NO_ERR_MSGS
78#else
79 ib::fatal(UT_LOCATION_HERE, ER_IB_ERR_ZLIB_MEM_ERROR)
80#endif
81 << "retval = Z_MEM_ERROR";
82 break;
83
84 case Z_DATA_ERROR:
85#ifdef UNIV_NO_ERR_MSGS
87#else
88 ib::fatal(UT_LOCATION_HERE, ER_IB_ERR_ZLIB_DATA_ERROR)
89#endif
90 << "retval = Z_DATA_ERROR";
91 break;
92
93 default:
94#ifdef UNIV_NO_ERR_MSGS
96#else
97 ib::fatal(UT_LOCATION_HERE, ER_IB_ERR_ZLIB_UNKNOWN_ERROR)
98#endif
99 << "retval = UNKNOWN_ERROR";
100 break;
101 }
102 }
103 }
104
105 /** @return the uncompressed sdi */
106 byte *get_data() const { return (m_uncomp_sdi); }
107
108 private:
109 /** Buffer to hold uncompressed SDI. memory allocated by caller */
111 /** Length of Outbuf Buffer */
112 uint32_t m_uncomp_len;
113 /** Input Compressed SDI */
115 /** Length of Compressed SDI */
116 uint32_t m_comp_len;
117};
118#endif
#define Z_BUF_ERROR
Definition: azlib.h:170
#define Z_OK
Definition: azlib.h:163
#define Z_DATA_ERROR
Definition: azlib.h:168
#define Z_MEM_ERROR
Definition: azlib.h:169
Decompress SDI record.
Definition: dict0sdi-decompress.h:34
void decompress()
Decompress the SDI and store in the buffer passed.
Definition: dict0sdi-decompress.h:49
uint32_t m_comp_len
Length of Compressed SDI.
Definition: dict0sdi-decompress.h:116
byte * m_uncomp_sdi
Buffer to hold uncompressed SDI.
Definition: dict0sdi-decompress.h:110
Sdi_Decompressor(byte *uncomp_sdi, uint32_t uncomp_len, byte *comp_sdi, uint32_t comp_len)
Definition: dict0sdi-decompress.h:36
uint32_t m_uncomp_len
Length of Outbuf Buffer.
Definition: dict0sdi-decompress.h:112
~Sdi_Decompressor()=default
byte * get_data() const
Definition: dict0sdi-decompress.h:106
byte * m_comp_sdi
Input Compressed SDI.
Definition: dict0sdi-decompress.h:114
The class error is used to emit error messages.
Definition: ut0log.h:231
The class fatal is used to emit an error message and stop the server by crashing it.
Definition: ut0log.h:253
#define UT_LOCATION_HERE
Definition: ut0core.h:73
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:105