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