MySQL 8.0.32
Source Code Documentation
iterator.h
Go to the documentation of this file.
1/* Copyright (c) 2019, 2022, 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 COMPRESSION_ITERATOR_INCLUDED
24#define COMPRESSION_ITERATOR_INCLUDED
25
26#include <memory>
29
30namespace binary_log {
31namespace transaction {
32namespace compression {
33
34/**
35 This is a commodity iterator over a buffer containing binlog
36 events inside. This buffer may be compressed, in which case,
37 this class shall decompress the buffer itself and provide the
38 iterator.
39
40 If iterating over a compressed buffer, this iterator shall
41 allocate memory internally to handle this. However, the ownership
42 of this memory is never handed over to any external entity and
43 as such, it is freed when this iterator is destroyed.
44 */
46 private:
48
49 public:
50 /**
51 Iterable buffer over an input buffer.
52
53 @param buffer input buffer
54 @param buffer_size the input buffer size
55 */
56 Iterable_buffer(const char *buffer, size_t buffer_size);
57
58 /**
59 Iterable buffer over a compressed input buffer.
60
61 @param buffer input buffer
62 @param buffer_size the input buffer size
63 @param uncompressed_size the size of the data uncompressed
64 @param comp_algo the compression algorithm (e.g., ZSTD)
65 */
66 Iterable_buffer(const char *buffer, size_t buffer_size,
67 size_t uncompressed_size, CompType comp_algo);
68
69 /**
70 Deletes the iterator and frees any buffers allocated during
71 while the iterator was in use.
72 */
73 virtual ~Iterable_buffer();
74
75 Iterable_buffer(const Iterable_buffer &rhs) = delete;
79
80 /**
81 Iterator class to allow iterating over a compressed log event buffer.
82
83 In order to fully understand this class implementation, please, check the
84 documentation on the Iterator concept requirements within the C++ standard
85 and the STL definition.
86 */
87 class iterator {
88 public:
89 using difference_type = std::ptrdiff_t;
90 using value_type = const char *;
91 using pointer = const char *;
92 using reference = const char *;
93 using iterator_category = std::forward_iterator_tag;
94
95 explicit iterator(Iterable_buffer &parent);
96 explicit iterator() = default;
97 /**
98 Copy constructor.
99
100 @param rhs object instance we pretend to copy from.
101 */
102 iterator(const iterator &rhs);
103 /**
104 Move constructor.
105
106 @param rhs object instance we pretend to move from.
107 */
108 iterator(iterator &&rhs);
109 virtual ~iterator();
110
112
113 // BASIC ITERATOR METHODS //
114 iterator &operator=(const iterator &rhs);
116 reference operator*() const;
117 // END / BASIC ITERATOR METHODS //
118 // INPUT ITERATOR METHODS //
119 iterator operator++(int);
120 pointer operator->() const;
121 bool operator==(iterator rhs) const;
122 bool operator!=(iterator rhs) const;
123 // END / INPUT ITERATOR METHODS //
124
125 // OUTPUT ITERATOR METHODS //
126 // reference operator*() const; <- already defined
127 // iterator operator++(int); <- already defined
128 // END / OUTPUT ITERATOR METHODS //
129 // FORWARD ITERATOR METHODS //
130 // Enable support for both input and output iterator <- already enabled
131 // END / FORWARD ITERATOR METHODS //
132
133 private:
134 bool has_next_buffer() const;
136 std::unique_ptr<binary_log::Event_reader> m_reader{nullptr};
137
138 friend class Iterable_buffer;
139 };
140
141 iterator begin();
142 iterator end();
143
144 friend class iterator;
145
146 private:
147 const char *m_compressed_buffer{nullptr};
149 std::unique_ptr<Decompressor> m_decoder{nullptr};
150 const char *m_decompressed_buffer{nullptr};
152};
153
154} // namespace compression
155} // namespace transaction
156} // namespace binary_log
157
158#endif
Iterator class to allow iterating over a compressed log event buffer.
Definition: iterator.h:87
std::forward_iterator_tag iterator_category
Definition: iterator.h:93
iterator & operator=(iterator &&rhs)
Definition: iterator.cpp:111
iterator & operator++()
Definition: iterator.cpp:122
bool operator!=(iterator rhs) const
Definition: iterator.cpp:164
reference operator*() const
Definition: iterator.cpp:137
bool operator==(iterator rhs) const
Definition: iterator.cpp:157
Iterable_buffer * m_target
Definition: iterator.h:135
bool has_next_buffer() const
Definition: iterator.cpp:169
std::ptrdiff_t difference_type
Definition: iterator.h:89
std::unique_ptr< binary_log::Event_reader > m_reader
Definition: iterator.h:136
pointer operator->() const
Definition: iterator.cpp:151
This is a commodity iterator over a buffer containing binlog events inside.
Definition: iterator.h:45
Iterable_buffer(const char *buffer, size_t buffer_size)
Iterable buffer over an input buffer.
Definition: iterator.cpp:32
Iterable_buffer(const Iterable_buffer &rhs)=delete
std::unique_ptr< Decompressor > m_decoder
Definition: iterator.h:149
const char * m_decompressed_buffer
Definition: iterator.h:150
iterator begin()
Definition: iterator.cpp:177
size_t m_compressed_buffer_size
Definition: iterator.h:148
size_t m_decompressed_buffer_size
Definition: iterator.h:151
virtual ~Iterable_buffer()
Deletes the iterator and frees any buffers allocated during while the iterator was in use.
Definition: iterator.cpp:79
const char * m_compressed_buffer
Definition: iterator.h:147
iterator end()
Definition: iterator.cpp:185
Iterable_buffer & operator=(Iterable_buffer &&rhs)=delete
Iterable_buffer & operator=(const Iterable_buffer &rhs)=delete
Contains the classes representing events operating in the replication stream properties.
Contains the class responsible for deserializing fields of an event previously stored in a buffer.
The namespace contains classes representing events that can occur in a replication stream.
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
size_t buffer_size(const ConstBufferSequence &buffers) noexcept
Definition: buffer.h:313