Debian Codegraph @

libbinlogevents/src/compression/decompressor.cpp

raw
1 /* Copyright (c) 2023, 2026, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24 #include <compression/decompressor.h>
25
26 namespace binary_log::transaction::compression {
27
28 type Decompressor::get_type_code() const { return do_get_type_code(); }
29
30 void Decompressor::reset() {
31 BAPI_TRACE;
32 do_reset();
33 }
34
35 void Decompressor::feed_char_t(const Char_t *input_data, Size_t input_size) {
36 BAPI_TRACE;
37 do_feed(input_data, input_size);
38 }
39
40 Decompress_status Decompressor::decompress(Managed_buffer_t &out,
41 Size_t output_size) {
42 BAPI_TRACE;
43 // Grow output buffer if needed.
44 switch (out.reserve_write_size(output_size)) {
45 case Grow_status_t::exceeds_max_size:
46 return Decompress_status::exceeds_max_size;
47 case Grow_status_t::out_of_memory:
48 reset();
49 return Decompress_status::out_of_memory;
50 case Grow_status_t::success:
51 break;
52 default:
53 assert(0);
54 }
55 auto [status, size] = decompress(out.write_part().begin(), output_size);
56 out.increase_position(size);
57 BAPI_LOG("info", BAPI_VAR(status) << " " << BAPI_VAR(size));
58 return status;
59 }
60
61 std::pair<Decompress_status, Decompressor::Size_t> Decompressor::decompress(
62 Char_t *out, Size_t output_size) {
63 BAPI_TRACE;
64 auto [status, size] = do_decompress(out, output_size);
65 if (status == Decompress_status::out_of_memory ||
66 status == Decompress_status::corrupted)
67 reset();
68 BAPI_LOG("info", BAPI_VAR(status) << " " << BAPI_VAR(size));
69 return std::make_pair(status, size);
70 }
71
72 Decompressor::Grow_constraint_t Decompressor::get_grow_constraint_hint() const {
73 return do_get_grow_constraint_hint();
74 }
75
76 Decompressor::Grow_constraint_t Decompressor::do_get_grow_constraint_hint()
77 const {
78 return Grow_constraint_t();
79 }
80
81 } // namespace binary_log::transaction::compression