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