paho-mqtt-cpp
MQTT C++ Client for POSIX and Windows
Loading...
Searching...
No Matches
types.h
Go to the documentation of this file.
1
6
7/*******************************************************************************
8 * Copyright (c) 2015-2017 Frank Pagliughi <fpagliughi@mindspring.com>
9 *
10 * All rights reserved. This program and the accompanying materials
11 * are made available under the terms of the Eclipse Public License v2.0
12 * and Eclipse Distribution License v1.0 which accompany this distribution.
13 *
14 * The Eclipse Public License is available at
15 * http://www.eclipse.org/legal/epl-v20.html
16 * and the Eclipse Distribution License is available at
17 * http://www.eclipse.org/org/documents/edl-v10.php.
18 *
19 * Contributors:
20 * Frank Pagliughi - initial implementation and documentation
21 *******************************************************************************/
22
23#ifndef __mqtt_types_h
24#define __mqtt_types_h
25
26#include <string>
27#include <vector>
28#include <memory>
29#include <chrono>
30
31namespace mqtt {
32
34// Basic data types
35
37using byte = uint8_t;
38
40using string = std::string;
42using binary = std::string;
43
45using string_ptr = std::shared_ptr<const string>;
47using binary_ptr = std::shared_ptr<const binary>;
48
50// General protocol enumerations
51
78 BANNED = 138,
103 MQTTPP_V3_CODE = 255 // This is not a protocol code; used internally by the library
105
107// Time functions
108
115template <class Rep, class Period>
116std::chrono::seconds to_seconds(const std::chrono::duration<Rep, Period>& dur) {
117 return std::chrono::duration_cast<std::chrono::seconds>(dur);
118}
119
126template <class Rep, class Period>
127long to_seconds_count(const std::chrono::duration<Rep, Period>& dur) {
128 return (long) to_seconds(dur).count();
129}
130
137template <class Rep, class Period>
138std::chrono::milliseconds to_milliseconds(const std::chrono::duration<Rep, Period>& dur) {
139 return std::chrono::duration_cast<std::chrono::milliseconds>(dur);
140}
141
148template <class Rep, class Period>
149long to_milliseconds_count(const std::chrono::duration<Rep, Period>& dur) {
150 return (long) to_milliseconds(dur).count();
151}
152
154// Misc
155
161inline bool to_bool(int n) { return n != 0; }
167inline int to_int(bool b) { return b ? (!0) : 0; }
168
175inline string to_string(const char* cstr) {
176 return cstr ? string(cstr) : string();
177}
178
180// end namespace mqtt
181}
182
183#endif // __mqtt_types_h
184
Definition async_client.h:49
std::shared_ptr< const binary > binary_ptr
Definition types.h:47
ReasonCode
Definition types.h:57
@ SERVER_SHUTTING_DOWN
Definition types.h:79
@ PACKET_IDENTIFIER_NOT_FOUND
Definition types.h:86
@ NO_SUBSCRIPTION_FOUND
Definition types.h:65
@ PACKET_IDENTIFIER_IN_USE
Definition types.h:85
@ BAD_AUTHENTICATION_METHOD
Definition types.h:80
@ MALFORMED_PACKET
Definition types.h:69
@ NOT_AUTHORIZED
Definition types.h:75
@ MAXIMUM_CONNECT_TIME
Definition types.h:100
@ TOPIC_NAME_INVALID
Definition types.h:84
@ NO_MATCHING_SUBSCRIBERS
Definition types.h:64
@ GRANTED_QOS_0
Definition types.h:60
@ IMPLEMENTATION_SPECIFIC_ERROR
Definition types.h:71
@ USE_ANOTHER_SERVER
Definition types.h:96
@ SUCCESS
Definition types.h:58
@ SUBSCRIPTION_IDENTIFIERS_NOT_SUPPORTED
Definition types.h:101
@ KEEP_ALIVE_TIMEOUT
Definition types.h:81
@ PAYLOAD_FORMAT_INVALID
Definition types.h:93
@ UNSPECIFIED_ERROR
Definition types.h:68
@ WILDCARD_SUBSCRIPTIONS_NOT_SUPPORTED
Definition types.h:102
@ QOS_NOT_SUPPORTED
Definition types.h:95
@ SERVER_UNAVAILABLE
Definition types.h:76
@ TOPIC_FILTER_INVALID
Definition types.h:83
@ RETAIN_NOT_SUPPORTED
Definition types.h:94
@ SHARED_SUBSCRIPTIONS_NOT_SUPPORTED
Definition types.h:98
@ QUOTA_EXCEEDED
Definition types.h:91
@ RE_AUTHENTICATE
Definition types.h:67
@ SERVER_BUSY
Definition types.h:77
@ SESSION_TAKEN_OVER
Definition types.h:82
@ SERVER_MOVED
Definition types.h:97
@ BANNED
Definition types.h:78
@ DISCONNECT_WITH_WILL_MESSAGE
Definition types.h:63
@ GRANTED_QOS_1
Definition types.h:61
@ NORMAL_DISCONNECTION
Definition types.h:59
@ BAD_USER_NAME_OR_PASSWORD
Definition types.h:74
@ MESSAGE_RATE_TOO_HIGH
Definition types.h:90
@ UNSUPPORTED_PROTOCOL_VERSION
Definition types.h:72
@ PROTOCOL_ERROR
Definition types.h:70
@ CONTINUE_AUTHENTICATION
Definition types.h:66
@ GRANTED_QOS_2
Definition types.h:62
@ ADMINISTRATIVE_ACTION
Definition types.h:92
@ TOPIC_ALIAS_INVALID
Definition types.h:88
@ PACKET_TOO_LARGE
Definition types.h:89
@ RECEIVE_MAXIMUM_EXCEEDED
Definition types.h:87
@ CLIENT_IDENTIFIER_NOT_VALID
Definition types.h:73
@ CONNECTION_RATE_EXCEEDED
Definition types.h:99
@ MQTTPP_V3_CODE
Definition types.h:103
long to_seconds_count(const std::chrono::duration< Rep, Period > &dur)
Definition types.h:127
bool to_bool(int n)
Definition types.h:161
std::string binary
Definition types.h:42
std::shared_ptr< const string > string_ptr
Definition types.h:45
std::chrono::milliseconds to_milliseconds(const std::chrono::duration< Rep, Period > &dur)
Definition types.h:138
string to_string(const char *cstr)
Definition types.h:175
std::chrono::seconds to_seconds(const std::chrono::duration< Rep, Period > &dur)
Definition types.h:116
std::string string
Definition types.h:40
uint8_t byte
Definition types.h:37
int to_int(bool b)
Definition types.h:167
long to_milliseconds_count(const std::chrono::duration< Rep, Period > &dur)
Definition types.h:149