MySQL 8.0.40
Source Code Documentation
classic_protocol_codec_error.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_CODEC_ERROR_H_
27#define MYSQL_ROUTER_CLASSIC_PROTOCOL_CODEC_ERROR_H_
28
29// error-domain for classic_protocol::codec errors
30
31#include <system_error> // error_code
32
33namespace classic_protocol {
34
35enum class codec_errc {
36 // precondition failed like "first byte == cmd_byte()"
37 invalid_input = 1,
38 // not enough input to satisfy the length requirements like "FixedInt<1>"
40 // no nul-terminator found in input
42 // capability not supported for this message
44 // statement-id not found
46 // field-type unknown
48};
49} // namespace classic_protocol
50
51namespace std {
52template <>
53struct is_error_code_enum<classic_protocol::codec_errc>
54 : public std::true_type {};
55} // namespace std
56
57namespace classic_protocol {
58inline const std::error_category &codec_category() noexcept {
59 class error_category_impl : public std::error_category {
60 public:
61 const char *name() const noexcept override { return "codec"; }
62 std::string message(int ev) const override {
63 switch (static_cast<codec_errc>(ev)) {
65 return "invalid input";
67 return "input too short";
69 return "missing nul-terminator";
71 return "capability not supported";
73 return "statement-id not found";
75 return "unknown field-type";
76 default:
77 return "unknown";
78 }
79 }
80 };
81
82 static error_category_impl instance;
83 return instance;
84}
85
86inline std::error_code make_error_code(codec_errc e) noexcept {
87 return {static_cast<int>(e), codec_category()};
88}
89
90} // namespace classic_protocol
91
92#endif
Definition: classic_protocol_binary.h:39
const std::error_category & codec_category() noexcept
Definition: classic_protocol_codec_error.h:58
std::error_code make_error_code(codec_errc e) noexcept
Definition: classic_protocol_codec_error.h:86
codec_errc
Definition: classic_protocol_codec_error.h:35
Definition: gcs_xcom_synode.h:64
case opt name
Definition: sslopt-case.h:33