File: Message.h

package info (click to toggle)
js8call 2.2.0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 22,416 kB
  • sloc: cpp: 563,285; f90: 9,265; ansic: 937; python: 132; sh: 93; makefile: 6
file content (44 lines) | stat: -rw-r--r-- 1,041 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef MESSAGE_H
#define MESSAGE_H

/**
 * (C) 2018 Jordan Sherer <kn4crd@gmail.com> - All Rights Reserved
 **/

#include <QMap>
#include <QByteArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QString>
#include <QVariant>


class Message {
public:
    Message();
    Message(QString const &type, QString const &value="");
    Message(QString const &type, QString const &value, QMap<QString, QVariant> const &params);

    void read(const QJsonObject &json);
    void write(QJsonObject &json) const;

    QByteArray toJson() const;
    QVariantMap toVariantMap() const;

    QString type() const { return type_; }
    void setType(QString type){ type_ = type; }

    QString value() const { return value_; }
    void setValue(QString value){ value_ = value; }
    qint64 id() const { return params_.value("_ID").toLongLong(); }
    qint64 ensureId();
    QMap<QString, QVariant> params() const { return params_; }

private:
    QString type_;
    QString value_;
    QMap<QString, QVariant> params_;
};


#endif // MESSAGE_H