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