async_mqtt 5.0.0
Loading...
Searching...
No Matches
connect_return_code.hpp
1// Copyright Takatoshi Kondo 2022
2//
3// Distributed under the Boost Software License, Version 1.0.
4// (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7#if !defined(ASYNC_MQTT_PACKET_CONNECT_RETURN_CODE_HPP)
8#define ASYNC_MQTT_PACKET_CONNECT_RETURN_CODE_HPP
9
10#include <cstdint>
11#include <ostream>
12
13
14namespace async_mqtt {
15
16enum class connect_return_code : std::uint8_t {
17 accepted = 0,
18 unacceptable_protocol_version = 1,
19 identifier_rejected = 2,
20 server_unavailable = 3,
21 bad_user_name_or_password = 4,
22 not_authorized = 5,
23};
24
25constexpr
26char const* connect_return_code_to_str(connect_return_code v) {
27 char const * const str[] = {
28 "accepted",
29 "unacceptable_protocol_version",
30 "identifier_rejected",
31 "server_unavailable",
32 "bad_user_name_or_password",
33 "not_authorized"
34 };
35 if (static_cast<std::uint8_t>(v) < sizeof(str)) return str[static_cast<std::uint8_t>(v)];
36 return "unknown_connect_return_code";
37}
38
39inline
40std::ostream& operator<<(std::ostream& os, connect_return_code val)
41{
42 os << connect_return_code_to_str(val);
43 return os;
44}
45
46} // namespace async_mqtt
47
48#endif // ASYNC_MQTT_PACKET_CONNECT_RETURN_CODE_HPP