MySQL 9.1.0
Source Code Documentation
zstd_dec.h
Go to the documentation of this file.
1/* Copyright (c) 2019, 2024, 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#ifndef MYSQL_BINLOG_EVENT_COMPRESSION_ZSTD_DEC_H
25#define MYSQL_BINLOG_EVENT_COMPRESSION_ZSTD_DEC_H
26
27#define ZSTD_STATIC_LINKING_ONLY 1
28#include <zstd.h>
29
30#include "mysql/allocators/memory_resource.h" // Memory_resource
33
35
36/// Decompressor class that uses the ZSTD library.
37class Zstd_dec : public Decompressor {
38 public:
39 using typename Decompressor::Char_t;
41 using typename Decompressor::Size_t;
43 static constexpr type type_code = ZSTD;
44
45 Zstd_dec(const Memory_resource_t &memory_resource = Memory_resource_t());
46 ~Zstd_dec() override;
47
48 Zstd_dec(const Zstd_dec &) = delete;
49 Zstd_dec(const Zstd_dec &&) = delete;
50 Zstd_dec &operator=(const Zstd_dec &) = delete;
51 Zstd_dec &operator=(const Zstd_dec &&) = delete;
52
53 private:
54 /// @return ZSTD
55 type do_get_type_code() const override;
56
57 /// @copydoc Decompressor::do_reset
58 void do_reset() override;
59
60 /// @copydoc Decompressor::do_feed
61 void do_feed(const Char_t *input_data, Size_t input_size) override;
62
63 /// @copydoc Decompressor::do_decompress
64 [[NODISCARD]] std::pair<Decompress_status, Size_t> do_decompress(
65 Char_t *out, Size_t output_size) override;
66
67 /// @copydoc Decompressor::do_get_grow_constraint_hint
69
70 /// Deallocate the ZSTD decompression context.
71 void destroy();
72
73 /// ZSTD decompression context object.
74 ZSTD_DStream *m_ctx{nullptr};
75
76 /// ZSTD input buffer.
77 ZSTD_inBuffer m_ibuf{nullptr, 0, 0};
78
79 bool m_frame_boundary = false;
80
81 /// Instrumented memory allocator object
83
84 /// ZSTD memory allocator objects and functions
85 ZSTD_customMem m_zstd_custom_mem;
86 static void *zstd_mem_res_alloc(void *opaque, size_t size);
87 static void zstd_mem_res_free(void *opaque, void *address);
88};
89
90} // namespace mysql::binlog::event::compression
91
92#endif // MYSQL_BINLOG_EVENT_COMPRESSION_ZSTD_DEC_H
Polymorphism-free memory resource class with custom allocator and deallocator functions.
Definition: memory_resource.h:88
Abstract base class for decompressors.
Definition: decompressor.h:57
mysql::containers::buffers::Buffer_view< Char_t >::Size_t Size_t
Definition: decompressor.h:60
unsigned char Char_t
Definition: decompressor.h:59
mysql::containers::buffers::Grow_constraint Grow_constraint_t
Definition: decompressor.h:62
Decompressor class that uses the ZSTD library.
Definition: zstd_dec.h:37
static constexpr type type_code
Definition: zstd_dec.h:43
Zstd_dec & operator=(const Zstd_dec &&)=delete
std::pair< Decompress_status, Size_t > do_decompress(Char_t *out, Size_t output_size) override
Implement decompress.
Definition: zstd_dec.cpp:72
type do_get_type_code() const override
Definition: zstd_dec.cpp:45
static void * zstd_mem_res_alloc(void *opaque, size_t size)
Definition: zstd_dec.cpp:153
ZSTD_DStream * m_ctx
ZSTD decompression context object.
Definition: zstd_dec.h:74
void destroy()
Deallocate the ZSTD decompression context.
Definition: zstd_dec.cpp:38
Memory_resource_t m_memory_resource
Instrumented memory allocator object.
Definition: zstd_dec.h:82
static void zstd_mem_res_free(void *opaque, void *address)
Definition: zstd_dec.cpp:158
void do_feed(const Char_t *input_data, Size_t input_size) override
Implement feed.
Definition: zstd_dec.cpp:59
ZSTD_inBuffer m_ibuf
ZSTD input buffer.
Definition: zstd_dec.h:77
Grow_constraint_t do_get_grow_constraint_hint() const override
Implement get_grow_constraint_hint.
Definition: zstd_dec.cpp:144
ZSTD_customMem m_zstd_custom_mem
ZSTD memory allocator objects and functions.
Definition: zstd_dec.h:85
void do_reset() override
Implement do_reset.
Definition: zstd_dec.cpp:47
mysql::allocators::Memory_resource Memory_resource_t
Definition: zstd_dec.h:42
Zstd_dec(const Memory_resource_t &memory_resource=Memory_resource_t())
Definition: zstd_dec.cpp:30
Zstd_dec & operator=(const Zstd_dec &)=delete
bool m_frame_boundary
Definition: zstd_dec.h:79
~Zstd_dec() override
Definition: zstd_dec.cpp:36
Description of a heuristic to determine how much memory to allocate.
Definition: grow_constraint.h:66
Class that wraps resources in a polymorphic manner.
Definition: base.cpp:27
@ ZSTD
Definition: base.h:42
size_t size(const char *const c)
Definition: base64.h:46
#define NODISCARD
The function attribute [[NODISCARD]] is a replacement for [[nodiscard]] to workaround a gcc bug.
Definition: nodiscard.h:47