1 /* Copyright (c) 2019, 2020, Oracle and/or its affiliates. All rights reserved.
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 COMPRESSION_NONE_INCLUDED
24 #define COMPRESSION_NONE_INCLUDED
25 
26 #include "base.h"
27 
28 namespace binary_log {
29 namespace transaction {
30 namespace compression {
31 
32 /**
33   This compressor does not compress. The only thing that it does
34   is to copy the data from the input to the output buffer.
35  */
36 class None_comp : public Compressor {
37  public:
38   None_comp() = default;
39 
40   /**
41     No op member function.
42    */
43   virtual void set_compression_level(unsigned int compression_level) override;
44 
45   /**
46     Shall get the compressor type code.
47 
48     @return the compressor type code.
49    */
50   virtual type compression_type_code() override;
51 
52   /**
53     No op member function.
54 
55     @return false on success, true otherwise.
56    */
57   virtual bool open() override;
58 
59   /**
60     This member function shall simply copy the input buffer to the
61     output buffer. It shall grow the output buffer if needed.
62 
63     @param data a pointer to the buffer holding the data to compress
64     @param length the size of the data to compress.
65 
66     @return false on success, true otherwise.
67    */
68   virtual std::tuple<std::size_t, bool> compress(const unsigned char *data,
69                                                  size_t length) override;
70 
71   /**
72     No op member function.
73 
74     @return false on success, true otherwise.
75    */
76   virtual bool close() override;
77 };
78 
79 /**
80   This decompressor does not decompress. The only thing that it
81   does is to copy the data from the input to the output buffer.
82  */
83 class None_dec : public Decompressor {
84  private:
85   None_dec &operator=(const None_dec &rhs) = delete;
86   None_dec(const None_dec &) = delete;
87 
88  public:
89   None_dec() = default;
90 
91   /**
92     Shall return the compression type code.
93 
94     @return the compression type code.
95    */
96   virtual type compression_type_code() override;
97 
98   /**
99     No op member function.
100 
101     @return false on success, true otherwise.
102    */
103   virtual bool open() override;
104 
105   /**
106     This member function shall simply copy the input buffer to the
107     output buffer. It shall grow the output buffer if needed.
108 
109     @param data a pointer to the buffer holding the data to decompress
110     @param length the size of the data to decompress.
111 
112     @return false on success, true otherwise.
113    */
114   virtual std::tuple<std::size_t, bool> decompress(const unsigned char *data,
115                                                    size_t length) override;
116 
117   /**
118     No op member function.
119 
120     @return false on success, true otherwise.
121    */
122   virtual bool close() override;
123 };
124 
125 }  // namespace compression
126 }  // namespace transaction
127 }  // namespace binary_log
128 #endif
129