MySQL 8.4.3
Source Code Documentation
protocol.h
Go to the documentation of this file.
1/*
2Copyright (c) 2016, 2024, Oracle and/or its affiliates.
3
4This program is free software; you can redistribute it and/or modify
5it under the terms of the GNU General Public License, version 2.0,
6as published by the Free Software Foundation.
7
8This program is designed to work with certain software (including
9but not limited to OpenSSL) that is licensed under separate terms,
10as designated in a particular file or component or in included license
11documentation. The authors of MySQL hereby grant you an additional
12permission to link the program and your derivative works with the
13separately licensed software that they have either included with
14the program or referenced in the documentation.
15
16This program is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with this program; if not, write to the Free Software
23Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25#ifndef ROUTING_PROTOCOL_INCLUDED
26#define ROUTING_PROTOCOL_INCLUDED
27
29
30#include <stdexcept>
31#include <string>
32
33class Protocol final {
34 public:
36
37 static inline Type get_default() { return Type::kClassicProtocol; }
38
39 /** @brief Returns type of the protocol by its name
40 */
41 static Type get_by_name(const std::string &name) {
43
44 if (name == "classic") {
45 /* already set */
46 } else if (name == "x") {
48 } else {
49 throw std::invalid_argument("Invalid protocol name: '" + name + "'");
50 }
51
52 return result;
53 }
54
55 static std::string to_string(const Type &type) {
56 std::string result;
57
58 switch (type) {
60 result = "classic";
61 break;
63 result = "x";
64 }
65
66 return result;
67 }
68
69 /** @brief Returns default port for the selected protocol
70 */
71 static uint16_t get_default_port(Type type) {
72 uint16_t result{0};
73
74 switch (type) {
77 break;
80 break;
81 default:
82 throw std::invalid_argument("Invalid protocol: " +
83 std::to_string(static_cast<int>(type)));
84 }
85
86 return result;
87 }
88
89 private:
90 /** @brief default server ports for supported protocols */
91 static constexpr uint16_t kClassicProtocolDefaultPort{3306};
92 static constexpr uint16_t kXProtocolDefaultPort{33060};
93};
94
95#endif // ROUTING_PROTOCOL_INCLUDED
Type
supported protocols
Definition: base_protocol.h:32
Definition: protocol.h:33
static Type get_by_name(const std::string &name)
Returns type of the protocol by its name.
Definition: protocol.h:41
static Type get_default()
Definition: protocol.h:37
static std::string to_string(const Type &type)
Definition: protocol.h:55
virtual enum enum_protocol_type type() const =0
static constexpr uint16_t kXProtocolDefaultPort
Definition: protocol.h:92
static constexpr uint16_t kClassicProtocolDefaultPort
default server ports for supported protocols
Definition: protocol.h:91
static uint16_t get_default_port(Type type)
Returns default port for the selected protocol.
Definition: protocol.h:71
static std::string to_string(const LEX_STRING &str)
Definition: lex_string.h:50
struct result result
Definition: result.h:34
case opt name
Definition: sslopt-case.h:29
Definition: result.h:30