Debian Codegraph @

libbinlogevents/include/codecs/binary.h

raw
1 /* Copyright (c) 2019, 2026, 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
27 #include "libbinlogevents/include/binary_log.h"
28 #include "libbinlogevents/include/codecs/base.h"
29
30 namespace binary_log {
31 namespace codecs {
32 namespace binary {
33
34 /**
35 This is the abstract and base class for binary log BINARY codecs.
36 */
37 class Base_codec : public binary_log::codecs::Codec {
38 protected:
39 Event_reader *m_reader;
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 */
56 class Transaction_payload : public Base_codec {
57 public:
58 /**
59 The on-the-wire fields
60 */
61 enum fields {
62 /** Marks the end of the payload header. */
63 OTW_PAYLOAD_HEADER_END_MARK = 0,
64
65 /** The payload field */
66 OTW_PAYLOAD_SIZE_FIELD = 1,
67
68 /** The compression type field */
69 OTW_PAYLOAD_COMPRESSION_TYPE_FIELD = 2,
70
71 /** The uncompressed size field */
72 OTW_PAYLOAD_UNCOMPRESSED_SIZE_FIELD = 3,
73
74 /** Other fields are appended here. */
75 };
76
77 Transaction_payload() = default;
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 */
114 class Heartbeat : public Base_codec {
115 public:
116 /**
117 The on-the-wire fields
118 */
119 enum fields {
120 /** Marks the end of the fields. */
121 OTW_HB_HEADER_END_MARK = 0,
122
123 /** The log file name */
124 OTW_HB_LOG_FILENAME_FIELD = 1,
125
126 /** The log position field */
127 OTW_HB_LOG_POSITION_FIELD = 2,
128
129 /** Other fields are appended here. */
130 };
131
132 Heartbeat() {}
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