-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathreader_context.hpp
More file actions
82 lines (67 loc) · 2.82 KB
/
reader_context.hpp
File metadata and controls
82 lines (67 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) 2023-2024 Percona and/or its affiliates.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, version 2.0,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License, version 2.0, for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#ifndef BINSRV_EVENT_READER_CONTEXT_HPP
#define BINSRV_EVENT_READER_CONTEXT_HPP
#include "binsrv/event/reader_context_fwd.hpp" // IWYU pragma: export
#include <cstdint>
#include "binsrv/replication_mode_type_fwd.hpp"
#include "binsrv/event/common_header_fwd.hpp"
#include "binsrv/event/event_fwd.hpp"
#include "binsrv/event/protocol_traits.hpp"
namespace binsrv::event {
class [[nodiscard]] reader_context {
friend class event;
public:
reader_context(std::uint32_t encoded_server_version, bool verify_checksum,
replication_mode_type replication_mode);
[[nodiscard]] std::uint32_t
get_current_encoded_server_version() const noexcept {
return encoded_server_version_;
}
[[nodiscard]] bool get_current_verify_checksum() const noexcept {
return verify_checksum_;
}
[[nodiscard]] std::size_t
get_current_post_header_length(code_type code) const noexcept;
[[nodiscard]] std::uint32_t get_current_position() const noexcept {
return position_;
}
private:
// this class implements the logic of the following state machine
// (ROTATE(artificial) FORMAT_DESCRIPTION <ANY>* (ROTATE|STOP)?)+
enum class state_type : std::uint8_t {
initial,
rotate_artificial_processed,
format_description_processed
};
state_type state_{state_type::initial};
std::uint32_t encoded_server_version_;
bool verify_checksum_;
replication_mode_type replication_mode_;
post_header_length_container post_header_lengths_{};
std::uint32_t position_{0U};
void process_event(const event ¤t_event);
[[nodiscard]] bool process_event_in_initial_state(const event ¤t_event);
[[nodiscard]] bool process_event_in_rotate_artificial_processed_state(
const event ¤t_event);
[[nodiscard]] bool process_event_in_format_description_processed_state(
const event ¤t_event);
void validate_position_and_advance(const common_header &common_header);
[[nodiscard]] static const post_header_length_container &
get_hardcoded_post_header_lengths(
std::uint32_t encoded_server_version) noexcept;
};
} // namespace binsrv::event
#endif // BINSRV_EVENT_READER_CONTEXT_HPP