File indexing completed on 2025-09-17 08:38:22
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_MQTT5_ERROR_HPP
0009 #define BOOST_MQTT5_ERROR_HPP
0010
0011 #include <boost/asio/error.hpp>
0012
0013 #include <cstdint>
0014 #include <ostream>
0015 #include <string>
0016
0017 namespace boost::mqtt5 {
0018
0019
0020
0021
0022
0023
0024
0025 enum class disconnect_rc_e : uint8_t {
0026
0027 normal_disconnection = 0x00,
0028
0029
0030
0031 disconnect_with_will_message = 0x04
0032 };
0033
0034 namespace detail {
0035
0036 enum class disconnect_rc_e : uint8_t {
0037 normal_disconnection = 0x00,
0038 disconnect_with_will_message = 0x04,
0039
0040 unspecified_error = 0x80,
0041 malformed_packet = 0x81,
0042 protocol_error = 0x82,
0043 implementation_specific_error = 0x83,
0044 topic_name_invalid = 0x90,
0045 receive_maximum_exceeded = 0x93,
0046 topic_alias_invalid = 0x94,
0047 packet_too_large = 0x95,
0048 message_rate_too_high = 0x96,
0049 quota_exceeded = 0x97,
0050 administrative_action = 0x98,
0051 payload_format_invalid = 0x99
0052 };
0053
0054 }
0055
0056
0057 namespace client {
0058
0059
0060
0061
0062
0063 enum class error : int {
0064
0065 malformed_packet = 100,
0066
0067
0068 packet_too_large,
0069
0070
0071 session_expired,
0072
0073
0074 pid_overrun,
0075
0076
0077 invalid_topic,
0078
0079
0080
0081 qos_not_supported,
0082
0083
0084 retain_not_available,
0085
0086
0087 topic_alias_maximum_reached,
0088
0089
0090
0091 wildcard_subscription_not_available,
0092
0093
0094 subscription_identifier_not_available,
0095
0096
0097 shared_subscription_not_available
0098 };
0099
0100
0101 inline std::string client_error_to_string(error err) {
0102 switch (err) {
0103 case error::malformed_packet:
0104 return "The packet is malformed";
0105 case error::packet_too_large:
0106 return "The packet has exceeded the Maximum Packet Size "
0107 "the Server is willing to accept";
0108 case error::session_expired:
0109 return "The Client's session does not exist or it has expired";
0110 case error::pid_overrun:
0111 return "There are no more available Packet Identifiers to use";
0112 case error::invalid_topic:
0113 return "The Topic is invalid and "
0114 "does not conform to the specification";
0115 case error::qos_not_supported:
0116 return "The Server does not support the specified QoS";
0117 case error::retain_not_available:
0118 return "The Server does not support retained messages";
0119 case error::topic_alias_maximum_reached:
0120 return "The Client attempted to send a Topic Alias "
0121 "that is greater than Topic Alias Maximum";
0122 case error::wildcard_subscription_not_available:
0123 return "The Server does not support Wildcard Subscriptions";
0124 case error::subscription_identifier_not_available:
0125 return "The Server does not support this Subscription Identifier";
0126 case error::shared_subscription_not_available:
0127 return "The Server does not support Shared Subscriptions";
0128 default:
0129 return "Unknown client error";
0130 }
0131 }
0132
0133 struct client_ec_category : public boost::system::error_category {
0134 const char* name() const noexcept override { return "mqtt_client_error"; }
0135 std::string message(int ev) const noexcept override {
0136 return client_error_to_string(static_cast<error>(ev));
0137 }
0138 };
0139
0140
0141 inline const client_ec_category& get_error_code_category() {
0142 static client_ec_category cat;
0143 return cat;
0144 }
0145
0146
0147 inline boost::system::error_code make_error_code(error r) {
0148 return { static_cast<int>(r), get_error_code_category() };
0149 }
0150
0151 inline std::ostream& operator<<(std::ostream& os, const error& err) {
0152 os << get_error_code_category().name() << ":" << static_cast<int>(err);
0153 return os;
0154 }
0155
0156 }
0157
0158 }
0159
0160 namespace boost::system {
0161
0162 template <>
0163 struct is_error_code_enum <boost::mqtt5::client::error> : std::true_type {};
0164
0165 }
0166
0167
0168 #endif