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