1/* Copyright (c) 2019, 2023, 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 also distributed 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 included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23#ifndef MY_COMPRESS_INCLUDED
24#define MY_COMPRESS_INCLUDED
25
26/* List of valid values for compression_algorithm */
27enum enum_compression_algorithm {
28 MYSQL_UNCOMPRESSED = 1,
29 MYSQL_ZLIB,
30 MYSQL_ZSTD,
31 MYSQL_INVALID
32};
33
34/**
35 Compress context information. relating to zlib compression.
36*/
37
38typedef struct mysql_zlib_compress_context {
39 /**
40 Compression level to use in zlib compression.
41 */
42 unsigned int compression_level;
43} mysql_zlib_compress_context;
44
45typedef struct ZSTD_CCtx_s ZSTD_CCtx;
46typedef struct ZSTD_DCtx_s ZSTD_DCtx;
47
48/**
49 Compress context information relating to zstd compression.
50*/
51
52typedef struct mysql_zstd_compress_context {
53 /**
54 Pointer to compressor context.
55 */
56 ZSTD_CCtx *cctx;
57 /**
58 Pointer to decompressor context.
59 */
60 ZSTD_DCtx *dctx;
61 /**
62 Compression level to use in zstd compression.
63 */
64 unsigned int compression_level;
65} mysql_zstd_compress_context;
66
67/**
68 Compression context information.
69 It encapsulate the context information based on compression method and
70 presents a generic struct.
71*/
72
73typedef struct mysql_compress_context {
74 enum enum_compression_algorithm algorithm; ///< Compression algorithm name.
75 union {
76 mysql_zlib_compress_context zlib_ctx; ///< Context information of zlib.
77 mysql_zstd_compress_context zstd_ctx; ///< Context information of zstd.
78 } u;
79} mysql_compress_context;
80
81/**
82 Get default compression level corresponding to a given compression method.
83
84 @param algorithm Compression Method. Possible values are zlib or zstd.
85
86 @return an unsigned int representing default compression level.
87 6 is the default compression level for zlib and 3 is the
88 default compression level for zstd.
89*/
90
91unsigned int mysql_default_compression_level(
92 enum enum_compression_algorithm algorithm);
93
94/**
95 Initialize a compress context object to be associated with a NET object.
96
97 @param cmp_ctx Pointer to compression context.
98 @param algorithm Compression algorithm.
99 @param compression_level Compression level corresponding to the compression
100 algorithm.
101*/
102
103void mysql_compress_context_init(mysql_compress_context *cmp_ctx,
104 enum enum_compression_algorithm algorithm,
105 unsigned int compression_level);
106/**
107 Deinitialize the compression context allocated.
108
109 @param mysql_compress_ctx Pointer to Compression context.
110*/
111
112void mysql_compress_context_deinit(mysql_compress_context *mysql_compress_ctx);
113
114#endif // MY_COMPRESS_INCLUDED
115

source code of include/mysql/my_compress.h