Initial commit

This commit is contained in:
github-classroom[bot]
2024-01-20 10:43:33 +00:00
committed by GitHub
commit b3cc535790
5 changed files with 229 additions and 0 deletions

62
stompframe.h Normal file
View File

@@ -0,0 +1,62 @@
#pragma once
#include <QString>
#include <QPair>
#include <QByteArray>
#include <QMap>
#include <QIODevice>
#include <QTextStream>
class STOMPFrame {
public:
enum Command {
INVALID,
// Client messages
STOMP, SEND, SUBSCRIBE, UNSUBSCRIBE, BEGIN, COMMIT, ABORT, ACK, NACK, DISCONNECT,
// Server messages
CONNECTED, MESSAGE, RECEIPT, ERROR
};
explicit STOMPFrame(Command command, std::initializer_list<QPair<QString,QString>> headers = {}, const QByteArray& body = {});
bool isNull() const {
return command_ == INVALID;
}
Command command() const {
return command_;
}
void setCommand(Command command) {
command_ = command;
}
const QMap<QString, QString>& headers() const {
return headers_;
}
void setHeaders(const QMap<QString, QString>& headers) {
headers_ = headers;
}
const QByteArray& body() const {
return body_;
}
void setBody(const QByteArray& body) {
body_ = body;
}
qint64 send(QIODevice& device);
static STOMPFrame receive(QIODevice& device);
private:
STOMPFrame() = default;
Command command_ = INVALID;
QMap<QString,QString> headers_;
QByteArray body_;
};
QTextStream& operator <<(QTextStream& out, STOMPFrame::Command command);