MySQL 9.1.0
Source Code Documentation
classic_protocol_frame.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef MYSQL_ROUTER_CLASSIC_PROTOCOL_FRAME_H_
27#define MYSQL_ROUTER_CLASSIC_PROTOCOL_FRAME_H_
28
29#include <cstddef> // size_t
30#include <cstdint> // uint8_t
31#include <utility> // move
32
33namespace classic_protocol {
34
35namespace frame {
36class Header {
37 public:
38 constexpr Header(size_t payload_size, uint8_t seq_id) noexcept
40
41 constexpr size_t payload_size() const noexcept { return payload_size_; }
42 constexpr uint8_t seq_id() const noexcept { return seq_id_; }
43
44 private:
45 size_t payload_size_{0};
46 uint8_t seq_id_{0};
47};
48
49constexpr bool operator==(const Header &a, const Header &b) {
50 return a.payload_size() == b.payload_size() && a.seq_id() == b.seq_id();
51}
52
53/**
54 * header of a compressed frame.
55 *
56 * used if client and server negotiated compression.
57 */
59 public:
60 constexpr CompressedHeader(size_t payload_size, uint8_t seq_id,
61 size_t uncompressed_size)
65
66 constexpr size_t payload_size() const noexcept { return payload_size_; }
67 constexpr uint8_t seq_id() const noexcept { return seq_id_; }
68 constexpr size_t uncompressed_size() const noexcept {
69 return uncompressed_size_;
70 }
71
72 private:
74 uint8_t seq_id_;
76};
77
78constexpr bool operator==(const CompressedHeader &a,
79 const CompressedHeader &b) {
80 return a.payload_size() == b.payload_size() && a.seq_id() == b.seq_id() &&
82}
83
84template <class PayloadType>
85class Frame {
86 public:
87 using value_type = PayloadType;
88
89 constexpr Frame(uint8_t seq_id, value_type v)
90 : seq_id_{seq_id}, payload_{std::move(v)} {}
91
92 constexpr uint8_t seq_id() const { return seq_id_; }
93 constexpr value_type payload() const { return payload_; }
94
95 private:
96 uint8_t seq_id_;
98};
99
100template <class T>
101bool operator==(const Frame<T> &a, const Frame<T> &b) {
102 return a.seq_id() == b.seq_id() && a.payload() == b.payload();
103}
104
105} // namespace frame
106
107} // namespace classic_protocol
108
109#endif
header of a compressed frame.
Definition: classic_protocol_frame.h:58
size_t uncompressed_size_
Definition: classic_protocol_frame.h:75
uint8_t seq_id_
Definition: classic_protocol_frame.h:74
constexpr CompressedHeader(size_t payload_size, uint8_t seq_id, size_t uncompressed_size)
Definition: classic_protocol_frame.h:60
constexpr uint8_t seq_id() const noexcept
Definition: classic_protocol_frame.h:67
size_t payload_size_
Definition: classic_protocol_frame.h:73
constexpr size_t payload_size() const noexcept
Definition: classic_protocol_frame.h:66
constexpr size_t uncompressed_size() const noexcept
Definition: classic_protocol_frame.h:68
Definition: classic_protocol_frame.h:85
constexpr value_type payload() const
Definition: classic_protocol_frame.h:93
value_type payload_
Definition: classic_protocol_frame.h:97
constexpr uint8_t seq_id() const
Definition: classic_protocol_frame.h:92
constexpr Frame(uint8_t seq_id, value_type v)
Definition: classic_protocol_frame.h:89
uint8_t seq_id_
Definition: classic_protocol_frame.h:96
PayloadType value_type
Definition: classic_protocol_frame.h:87
Definition: classic_protocol_frame.h:36
constexpr size_t payload_size() const noexcept
Definition: classic_protocol_frame.h:41
size_t payload_size_
Definition: classic_protocol_frame.h:45
constexpr Header(size_t payload_size, uint8_t seq_id) noexcept
Definition: classic_protocol_frame.h:38
uint8_t seq_id_
Definition: classic_protocol_frame.h:46
constexpr uint8_t seq_id() const noexcept
Definition: classic_protocol_frame.h:42
constexpr bool operator==(const Header &a, const Header &b)
Definition: classic_protocol_frame.h:49
Definition: classic_protocol_binary.h:39
Definition: gcs_xcom_synode.h:64