MySQL 9.1.0
Source Code Documentation
binary.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_CODECS_BINARY_H
25#define MYSQL_BINLOG_EVENT_CODECS_BINARY_H
26
29
31
32/**
33 This is the abstract and base class for binary log BINARY codecs.
34 */
36 protected:
38 inline Event_reader &reader() { return *m_reader; }
39
40 public:
41 std::pair<std::size_t, bool> decode(const unsigned char *from,
42 std::size_t size,
43 Binary_log_event &to) const override = 0;
44 std::pair<std::size_t, bool> encode(const Binary_log_event &from,
45 unsigned char *to,
46 std::size_t size) const override = 0;
47
48 Base_codec() = default;
49
50 // copy-move semantics
51 Base_codec(Base_codec &&) noexcept = default;
52 Base_codec &operator=(Base_codec &&) noexcept = default;
53 Base_codec(const Base_codec &) noexcept = default;
54 Base_codec &operator=(const Base_codec &) = default;
55
56 ~Base_codec() override = default;
57};
58
59/**
60 Binary codec for the transaction payload log event.
61 */
63 public:
64 /**
65 The on-the-wire fields
66 */
67 enum fields {
68 /** Marks the end of the payload header. */
69 OTW_PAYLOAD_HEADER_END_MARK = 0,
70
71 /** The payload field */
72 OTW_PAYLOAD_SIZE_FIELD = 1,
73
74 /** The compression type field */
75 OTW_PAYLOAD_COMPRESSION_TYPE_FIELD = 2,
76
77 /** The uncompressed size field */
78 OTW_PAYLOAD_UNCOMPRESSED_SIZE_FIELD = 3,
79
80 /** Other fields are appended here. */
81 };
82
84 /**
85 This member function shall decode the contents of the buffer provided and
86 fill in the event referenced. Note that the event provided needs to be of
87 type TRANSACTION_PAYLOAD_EVENT.
88
89 @param from the buffer to decode
90 @param size the size of the buffer to decode.
91 @param to the event to store the decoded information into.
92
93 @return a pair containing the amount of bytes decoded and whether there was
94 an error or not. False if no error, true otherwise.
95 */
96 std::pair<std::size_t, bool> decode(const unsigned char *from,
97 std::size_t size,
98 Binary_log_event &to) const override;
99
100 /**
101 This member function shall encode the contents of the event referenced and
102 store the result in the buffer provided. Note that the event referenced
103 needs to be of type TRANSACTION_PAYLOAD_EVENT.
104
105 @param from the event to encode.
106 @param to the buffer where to store the encoded event.
107 @param size the size of the buffer.
108
109 @return a pair containing the amount of bytes encoded and whether there was
110 an error or not.
111 */
112 std::pair<std::size_t, bool> encode(const Binary_log_event &from,
113 unsigned char *to,
114 std::size_t size) const override;
115};
116
117/**
118 Binary codec for the heartbeat log event.
119 */
120class Heartbeat : public Base_codec {
121 public:
122 /**
123 The on-the-wire fields
124 */
125 enum fields {
126 /** Marks the end of the fields. */
127 OTW_HB_HEADER_END_MARK = 0,
128
129 /** The log file name */
130 OTW_HB_LOG_FILENAME_FIELD = 1,
131
132 /** The log position field */
133 OTW_HB_LOG_POSITION_FIELD = 2,
134
135 /** Other fields are appended here. */
136 };
137
139 /**
140 This member function shall decode the contents of the buffer provided and
141 fill in the event referenced. Note that the event provided needs to be of
142 type HEARTBEAT_EVENT_V2.
143
144 @param from the buffer to decode
145 @param size the size of the buffer to decode.
146 @param to the event to store the decoded information into.
147
148 @return a pair containing the amount of bytes decoded and whether there was
149 an error or not. False if no error, true otherwise.
150 */
151 std::pair<std::size_t, bool> decode(const unsigned char *from,
152 std::size_t size,
153 Binary_log_event &to) const override;
154
155 /**
156 This member function shall encode the contents of the event referenced and
157 store the result in the buffer provided. Note that the event referenced
158 needs to be of type HEARTBEAT_EVENT_V2.
159
160 @param from the event to encode.
161 @param to the buffer where to store the encoded event.
162 @param size the size of the buffer.
163
164 @return a pair containing the amount of bytes encoded and whether there was
165 an error or not.
166 */
167 std::pair<std::size_t, bool> encode(const Binary_log_event &from,
168 unsigned char *to,
169 std::size_t size) const override;
170};
171
172} // namespace mysql::binlog::event::codecs::binary
173
174namespace [[deprecated]] binary_log {
175namespace [[deprecated]] codecs {
176namespace [[deprecated]] binary {
178} // namespace binary
179} // namespace codecs
180} // namespace binary_log
181
182#endif // MYSQL_BINLOG_EVENT_CODECS_BINARY_H
This is the abstract base class for binary log events.
Definition: binlog_event.h:851
Event_reader class purpose is to avoid out-of-buffer reads when deserializing binary log events and i...
Definition: event_reader.h:74
This is the abstract and base class for binary log codecs.
Definition: base.h:38
This is the abstract and base class for binary log BINARY codecs.
Definition: binary.h:35
std::pair< std::size_t, bool > encode(const Binary_log_event &from, unsigned char *to, std::size_t size) const override=0
Member function that shall encode the contents of the given binary log event into an in memory buffer...
std::pair< std::size_t, bool > decode(const unsigned char *from, std::size_t size, Binary_log_event &to) const override=0
Member function that shall decode the contents of the given buffer into a binary log event.
Event_reader * m_reader
Definition: binary.h:37
Base_codec(Base_codec &&) noexcept=default
Event_reader & reader()
Definition: binary.h:38
Binary codec for the heartbeat log event.
Definition: binary.h:120
fields
The on-the-wire fields.
Definition: binary.h:125
Binary codec for the transaction payload log event.
Definition: binary.h:62
fields
The on-the-wire fields.
Definition: binary.h:67
Definition: base.h:75
constexpr value_type binary
Definition: classic_protocol_constants.h:275
Definition: binary.cpp:29
size_t size(const char *const c)
Definition: base64.h:46