aboutsummaryrefslogtreecommitdiff
path: root/lib/application-service/definitions/protocol.cpp
blob: 04bb7dfc7d6a2376cc255918d3d1eb880df26978 (plain)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/******************************************************************************
 * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
 */

#include "protocol.h"

using namespace QMatrixClient;

QJsonObject QMatrixClient::toJson(const FieldType& pod)
{
    QJsonObject jo;
    addParam<>(jo, QStringLiteral("regexp"), pod.regexp);
    addParam<>(jo, QStringLiteral("placeholder"), pod.placeholder);
    return jo;
}

FieldType FromJsonObject<FieldType>::operator()(const QJsonObject& jo) const
{
    FieldType result;
    result.regexp =
        fromJson<QString>(jo.value("regexp"_ls));
    result.placeholder =
        fromJson<QString>(jo.value("placeholder"_ls));

    return result;
}

QJsonObject QMatrixClient::toJson(const ProtocolInstance& pod)
{
    QJsonObject jo;
    addParam<>(jo, QStringLiteral("desc"), pod.desc);
    addParam<IfNotEmpty>(jo, QStringLiteral("icon"), pod.icon);
    addParam<>(jo, QStringLiteral("fields"), pod.fields);
    addParam<>(jo, QStringLiteral("network_id"), pod.networkId);
    return jo;
}

ProtocolInstance FromJsonObject<ProtocolInstance>::operator()(const QJsonObject& jo) const
{
    ProtocolInstance result;
    result.desc =
        fromJson<QString>(jo.value("desc"_ls));
    result.icon =
        fromJson<QString>(jo.value("icon"_ls));
    result.fields =
        fromJson<QJsonObject>(jo.value("fields"_ls));
    result.networkId =
        fromJson<QString>(jo.value("network_id"_ls));

    return result;
}

QJsonObject QMatrixClient::toJson(const ThirdPartyProtocol& pod)
{
    QJsonObject jo;
    addParam<>(jo, QStringLiteral("user_fields"), pod.userFields);
    addParam<>(jo, QStringLiteral("location_fields"), pod.locationFields);
    addParam<>(jo, QStringLiteral("icon"), pod.icon);
    addParam<>(jo, QStringLiteral("field_types"), pod.fieldTypes);
    addParam<>(jo, QStringLiteral("instances"), pod.instances);
    return jo;
}

ThirdPartyProtocol FromJsonObject<ThirdPartyProtocol>::operator()(const QJsonObject& jo) const
{
    ThirdPartyProtocol result;
    result.userFields =
        fromJson<QStringList>(jo.value("user_fields"_ls));
    result.locationFields =
        fromJson<QStringList>(jo.value("location_fields"_ls));
    result.icon =
        fromJson<QString>(jo.value("icon"_ls));
    result.fieldTypes =
        fromJson<QHash<QString, FieldType>>(jo.value("field_types"_ls));
    result.instances =
        fromJson<QVector<ProtocolInstance>>(jo.value("instances"_ls));

    return result;
}