MqttBuffer.h
Go to the documentation of this file.
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * MqttMessage.h - C++ utilities to simplify handling MQTT messages and buffers
8  *
9  ****/
10 
11 #pragma once
12 
13 #include <mqtt-codec/src/message.h>
14 #include <Print.h>
15 
20 {
21 public:
22  MqttBuffer(const mqtt_buffer_t& buf) : buf(buf)
23  {
24  }
25 
26  operator String() const
27  {
28  return String(reinterpret_cast<const char*>(buf.data), buf.length);
29  }
30 
31  size_t printTo(Print& p) const
32  {
33  return p.write(buf.data, buf.length);
34  }
35 
36 private:
37  const mqtt_buffer_t& buf;
38 };
The String class.
Definition: WString.h:136
size_t printTo(Print &p) const
Definition: MqttBuffer.h:39
MqttBuffer(const mqtt_buffer_t &buf)
Definition: MqttBuffer.h:30
virtual size_t write(uint8_t c)=0
Writes a single character to output stream.
Provides formatted output to stream.
Definition: Print.h:36
Helper class to simplify printing and parsing message buffers.
Definition: MqttBuffer.h:19