-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcommon_header.hpp
More file actions
84 lines (67 loc) · 2.77 KB
/
common_header.hpp
File metadata and controls
84 lines (67 loc) · 2.77 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
83
84
// 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_COMMON_HEADER_HPP
#define BINSRV_EVENT_COMMON_HEADER_HPP
#include "binsrv/event/common_header_fwd.hpp" // IWYU pragma: export
#include <cstdint>
#include <ctime>
#include <string>
#include <string_view>
#include "binsrv/event/code_type_fwd.hpp"
#include "binsrv/event/common_header_flag_type_fwd.hpp"
#include "binsrv/event/protocol_traits_fwd.hpp"
#include "util/byte_span_fwd.hpp"
namespace binsrv::event {
class [[nodiscard]] common_header {
public:
static constexpr std::size_t size_in_bytes{default_common_header_length};
explicit common_header(util::const_byte_span portion);
[[nodiscard]] std::uint32_t get_timestamp_raw() const noexcept {
return timestamp_;
}
[[nodiscard]] std::time_t get_timestamp() const noexcept {
return static_cast<std::time_t>(get_timestamp_raw());
}
[[nodiscard]] std::string get_readable_timestamp() const;
[[nodiscard]] std::uint8_t get_type_code_raw() const noexcept {
return type_code_;
}
[[nodiscard]] code_type get_type_code() const noexcept {
return static_cast<code_type>(get_type_code_raw());
}
[[nodiscard]] std::string_view get_readable_type_code() const noexcept;
[[nodiscard]] std::uint32_t get_server_id_raw() const noexcept {
return server_id_;
}
[[nodiscard]] std::uint32_t get_event_size_raw() const noexcept {
return event_size_;
}
[[nodiscard]] std::uint32_t get_next_event_position_raw() const noexcept {
return next_event_position_;
}
[[nodiscard]] std::uint16_t get_flags_raw() const noexcept { return flags_; }
[[nodiscard]] common_header_flag_set get_flags() const noexcept;
[[nodiscard]] std::string get_readable_flags() const;
private:
// the members are deliberately reordered for better packing
std::uint32_t timestamp_{}; // 0
std::uint32_t server_id_{}; // 2
std::uint32_t event_size_{}; // 3
std::uint32_t next_event_position_{}; // 4
std::uint16_t flags_{}; // 5
std::uint8_t type_code_{}; // 1
};
} // namespace binsrv::event
#endif // BINSRV_EVENT_COMMON_HEADER_HPP