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 MY_COMPRESS_INCLUDED |
25 | #define MY_COMPRESS_INCLUDED |
26 | |
27 | /* List of valid values for compression_algorithm */ |
28 | enum enum_compression_algorithm { |
29 | MYSQL_UNCOMPRESSED = 1, |
30 | MYSQL_ZLIB, |
31 | MYSQL_ZSTD, |
32 | MYSQL_INVALID |
33 | }; |
34 | |
35 | /** |
36 | Compress context information. relating to zlib compression. |
37 | */ |
38 | |
39 | typedef struct mysql_zlib_compress_context { |
40 | /** |
41 | Compression level to use in zlib compression. |
42 | */ |
43 | unsigned int compression_level; |
44 | } mysql_zlib_compress_context; |
45 | |
46 | typedef struct ZSTD_CCtx_s ZSTD_CCtx; |
47 | typedef struct ZSTD_DCtx_s ZSTD_DCtx; |
48 | |
49 | /** |
50 | Compress context information relating to zstd compression. |
51 | */ |
52 | |
53 | typedef struct mysql_zstd_compress_context { |
54 | /** |
55 | Pointer to compressor context. |
56 | */ |
57 | ZSTD_CCtx *cctx; |
58 | /** |
59 | Pointer to decompressor context. |
60 | */ |
61 | ZSTD_DCtx *dctx; |
62 | /** |
63 | Compression level to use in zstd compression. |
64 | */ |
65 | unsigned int compression_level; |
66 | } mysql_zstd_compress_context; |
67 | |
68 | /** |
69 | Compression context information. |
70 | It encapsulate the context information based on compression method and |
71 | presents a generic struct. |
72 | */ |
73 | |
74 | typedef struct mysql_compress_context { |
75 | enum enum_compression_algorithm algorithm; ///< Compression algorithm name. |
76 | union { |
77 | mysql_zlib_compress_context zlib_ctx; ///< Context information of zlib. |
78 | mysql_zstd_compress_context zstd_ctx; ///< Context information of zstd. |
79 | } u; |
80 | } mysql_compress_context; |
81 | |
82 | /** |
83 | Get default compression level corresponding to a given compression method. |
84 | |
85 | @param algorithm Compression Method. Possible values are zlib or zstd. |
86 | |
87 | @return an unsigned int representing default compression level. |
88 | 6 is the default compression level for zlib and 3 is the |
89 | default compression level for zstd. |
90 | */ |
91 | |
92 | unsigned int mysql_default_compression_level( |
93 | enum enum_compression_algorithm algorithm); |
94 | |
95 | /** |
96 | Initialize a compress context object to be associated with a NET object. |
97 | |
98 | @param cmp_ctx Pointer to compression context. |
99 | @param algorithm Compression algorithm. |
100 | @param compression_level Compression level corresponding to the compression |
101 | algorithm. |
102 | */ |
103 | |
104 | void mysql_compress_context_init(mysql_compress_context *cmp_ctx, |
105 | enum enum_compression_algorithm algorithm, |
106 | unsigned int compression_level); |
107 | /** |
108 | Deinitialize the compression context allocated. |
109 | |
110 | @param mysql_compress_ctx Pointer to Compression context. |
111 | */ |
112 | |
113 | void mysql_compress_context_deinit(mysql_compress_context *mysql_compress_ctx); |
114 | |
115 | #endif // MY_COMPRESS_INCLUDED |
116 | |