24 #ifndef __mqtt_buffer_view_h
25 #define __mqtt_buffer_view_h
61 : data_(data), sz_(n) {}
68 : data_(str.
data()), sz_(str.
size()) {}
94 std::basic_string<value_type>
str()
const {
95 return std::basic_string<value_type>(data_, sz_);
102 static_assert(
sizeof(
char) ==
sizeof(T),
"can only get string for char or byte buffers");
103 return string(reinterpret_cast<const char*>(data_), sz_);
108 using string_view = buffer_view<char>;
111 using binary_view = buffer_view<char>;
118 #endif // __mqtt_buffer_view_h
const value_type & operator[](size_t i) const
Access an item in the view.
Definition: buffer_view.h:89
Basic types and type conversions for the Paho MQTT C++ library.
std::basic_string< value_type > str() const
Gets a copy of the view as a string.
Definition: buffer_view.h:94
size_type size() const
Gets the number of items in the view.
Definition: buffer_view.h:78
const value_type * data() const
Gets a pointer the first item in the view.
Definition: buffer_view.h:73
buffer_view(const std::basic_string< value_type > &str)
Constructs a buffer view to a whole string.
Definition: buffer_view.h:67
size_t size_type
The type used to specify number of items in the container.
Definition: buffer_view.h:46
buffer_view(const value_type *data, size_type n)
Constructs a buffer view.
Definition: buffer_view.h:60
string to_string() const
Gets a copy of the view as a string.
Definition: buffer_view.h:101
A reference to a contiguous sequence of items, with no ownership.
Definition: buffer_view.h:40
size_type length() const
Gets the number of items in the view.
Definition: buffer_view.h:83
T value_type
The type of items to be held in the queue.
Definition: buffer_view.h:44