Files
UvosSmartHomeInterface/src/broadcast.h

43 lines
681 B
C++

#ifndef BROADCAST_H
#define BROADCAST_H
#include <QIODevice>
#include <QObject>
#include <QString>
#include <QJsonObject>
class BroadCast: public QObject
{
Q_OBJECT
private:
static constexpr uint8_t MODE_PREPACKET = 0;
static constexpr uint8_t MODE_PACKET = 1;
QByteArray buffer_;
QIODevice* const iodevice_;
void write(const char * const buffer, const size_t length);
void write(const QByteArray& buffer);
void decode();
private slots:
void readyRead();
signals:
void gotJson(QJsonObject json);
public:
BroadCast(QIODevice* const iodevice = nullptr);
void sendJson(const QJsonObject& json);
};
#endif // BROADCAST_H