| 1 |
/* Copyright (c) 2019, 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/compressor.h> |
| 25 |
|
| 26 |
namespace binary_log::transaction::compression { |
| 27 |
|
| 28 |
type Compressor::get_type_code() const { return do_get_type_code(); } |
| 29 |
|
| 30 |
void Compressor::reset() { |
| 31 |
BAPI_TRACE; |
| 32 |
do_reset(); |
| 33 |
m_pending_input = false; |
| 34 |
m_empty = true; |
| 35 |
m_pledged_input_size = 0; |
| 36 |
} |
| 37 |
|
| 38 |
void Compressor::feed_char_t(const Char_t *input_data, Size_t input_size) { |
| 39 |
BAPI_TRACE; |
| 40 |
BAPI_LOG("info", BAPI_VAR(input_size)); |
| 41 |
assert(!m_pending_input); |
| 42 |
do_feed(input_data, input_size); |
| 43 |
m_pending_input = true; |
| 44 |
m_empty = false; |
| 45 |
} |
| 46 |
|
| 47 |
Compress_status Compressor::compress(Managed_buffer_sequence_t &out) { |
| 48 |
BAPI_TRACE; |
| 49 |
auto ret = do_compress(out); |
| 50 |
if (ret == Compress_status::out_of_memory) reset(); |
| 51 |
if (ret != Compress_status::exceeds_max_size) m_pending_input = false; |
| 52 |
BAPI_LOG("info", BAPI_VAR(ret) << " " << BAPI_VAR(out.read_part().size())); |
| 53 |
return ret; |
| 54 |
} |
| 55 |
|
| 56 |
Compress_status Compressor::finish(Managed_buffer_sequence_t &out) { |
| 57 |
BAPI_TRACE; |
| 58 |
// Consume all input, if not consumed already. |
| 59 |
auto compress_status = compress(out); |
| 60 |
if (compress_status != Compress_status::success) return compress_status; |
| 61 |
|
| 62 |
// Produce all output. |
| 63 |
auto ret = do_finish(out); |
| 64 |
if (ret == Compress_status::out_of_memory) reset(); |
| 65 |
if (ret != Compress_status::exceeds_max_size) m_pending_input = false; |
| 66 |
if (ret == Compress_status::success) m_empty = true; |
| 67 |
BAPI_LOG("info", BAPI_VAR(ret) << " " << BAPI_VAR(out.read_part().size())); |
| 68 |
return ret; |
| 69 |
} |
| 70 |
|
| 71 |
Compressor::Grow_constraint_t Compressor::get_grow_constraint_hint() const { |
| 72 |
return do_get_grow_constraint_hint(); |
| 73 |
} |
| 74 |
|
| 75 |
Compressor::Grow_constraint_t Compressor::do_get_grow_constraint_hint() const { |
| 76 |
return Grow_constraint_t(); |
| 77 |
} |
| 78 |
|
| 79 |
void Compressor::set_pledged_input_size(Size_t size) { |
| 80 |
assert(m_empty); |
| 81 |
m_pledged_input_size = size; |
| 82 |
do_set_pledged_input_size(size); |
| 83 |
} |
| 84 |
|
| 85 |
Compressor::Size_t Compressor::get_pledged_input_size() const { |
| 86 |
return m_pledged_input_size; |
| 87 |
} |
| 88 |
|
| 89 |
void Compressor::do_set_pledged_input_size([[maybe_unused]] Size_t size) {} |
| 90 |
|
| 91 |
} // namespace binary_log::transaction::compression |