libkazv
protocol.hpp
Go to the documentation of this file.
1 /******************************************************************************
2  * THIS FILE IS GENERATED - ANY EDITS WILL BE OVERWRITTEN
3  */
4 
5 #pragma once
6 
7 #include "types.hpp"
8 
9 
10 namespace Kazv::Api {
12 struct FieldType
13 {
14 
18  std::string regexp;
19 
21  std::string placeholder;
22 };
23 
24 }
25 namespace nlohmann
26 {
27 using namespace Kazv;
28 using namespace Kazv::Api;
29 template<>
30 struct adl_serializer<FieldType> {
31  static void to_json(json& jo, const FieldType &pod)
32  {
33  if (! jo.is_object()) { jo = json::object(); }
34 
35 
36  jo["regexp"s] = pod.regexp;
37 
38  jo["placeholder"s] = pod.placeholder;
39 
40  }
41  static void from_json(const json &jo, FieldType& result)
42  {
43 
44  if (jo.contains("regexp"s)) {
45  result.regexp = jo.at("regexp"s);
46  }
47  if (jo.contains("placeholder"s)) {
48  result.placeholder = jo.at("placeholder"s);
49  }
50 
51  }
52 };
53  }
54 
55  namespace Kazv::Api
56  {
57 
59 {
60 
62  std::string desc;
63 
66 
68  std::string networkId;
69 
72  std::optional<std::string> icon;
73 };
74 
75 }
76 namespace nlohmann
77 {
78 using namespace Kazv;
79 using namespace Kazv::Api;
80 template<>
81 struct adl_serializer<ProtocolInstance> {
82  static void to_json(json& jo, const ProtocolInstance &pod)
83  {
84  if (! jo.is_object()) { jo = json::object(); }
85 
86 
87  jo["desc"s] = pod.desc;
88 
89  jo["fields"s] = pod.fields;
90 
91  jo["network_id"s] = pod.networkId;
92 
93 
94  addToJsonIfNeeded(jo, "icon"s, pod.icon);
95  }
96  static void from_json(const json &jo, ProtocolInstance& result)
97  {
98 
99  if (jo.contains("desc"s)) {
100  result.desc = jo.at("desc"s);
101  }
102  if (jo.contains("fields"s)) {
103  result.fields = jo.at("fields"s);
104  }
105  if (jo.contains("network_id"s)) {
106  result.networkId = jo.at("network_id"s);
107  }
108  if (jo.contains("icon"s)) {
109  result.icon = jo.at("icon"s);
110  }
111 
112  }
113 };
114  }
115 
116  namespace Kazv::Api
117  {
118 
120 {
121 
126  immer::array<std::string> userFields;
127 
132  immer::array<std::string> locationFields;
133 
135  std::string icon;
136 
142  immer::map<std::string, FieldType> fieldTypes;
143 
147  immer::array<ProtocolInstance> instances;
148 };
149 
150 }
151 namespace nlohmann
152 {
153 using namespace Kazv;
154 using namespace Kazv::Api;
155 template<>
156 struct adl_serializer<ThirdPartyProtocol> {
157  static void to_json(json& jo, const ThirdPartyProtocol &pod)
158  {
159  if (! jo.is_object()) { jo = json::object(); }
160 
161 
162  jo["user_fields"s] = pod.userFields;
163 
164  jo["location_fields"s] = pod.locationFields;
165 
166  jo["icon"s] = pod.icon;
167 
168  jo["field_types"s] = pod.fieldTypes;
169 
170  jo["instances"s] = pod.instances;
171 
172  }
173  static void from_json(const json &jo, ThirdPartyProtocol& result)
174  {
175 
176  if (jo.contains("user_fields"s)) {
177  result.userFields = jo.at("user_fields"s);
178  }
179  if (jo.contains("location_fields"s)) {
180  result.locationFields = jo.at("location_fields"s);
181  }
182  if (jo.contains("icon"s)) {
183  result.icon = jo.at("icon"s);
184  }
185  if (jo.contains("field_types"s)) {
186  result.fieldTypes = jo.at("field_types"s);
187  }
188  if (jo.contains("instances"s)) {
189  result.instances = jo.at("instances"s);
190  }
191 
192  }
193 };
194  }
195 
196  namespace Kazv::Api
197  {
198 } // namespace Kazv::Api
Definition: jsonwrap.hpp:23
Definition: location.hpp:10
Definition: location.hpp:10
void addToJsonIfNeeded(json &j, std::string name, T &&arg)
Definition: types.hpp:80
nlohmann::json json
Definition: jsonwrap.hpp:20
Definition: location.hpp:27
Definition of valid values for a field.
Definition: protocol.hpp:13
std::string placeholder
An placeholder serving as a valid example of the field value.
Definition: protocol.hpp:21
std::string regexp
A regular expression for validation of a field's value.
Definition: protocol.hpp:18
Definition: protocol.hpp:59
std::string networkId
A unique identifier across all instances.
Definition: protocol.hpp:68
std::optional< std::string > icon
An optional content URI representing the protocol.
Definition: protocol.hpp:72
JsonWrap fields
Preset values for fields the client may use to search by.
Definition: protocol.hpp:65
std::string desc
A human-readable description for the protocol, such as the name.
Definition: protocol.hpp:62
Definition: protocol.hpp:120
std::string icon
A content URI representing an icon for the third party protocol.
Definition: protocol.hpp:135
immer::map< std::string, FieldType > fieldTypes
The type definitions for the fields defined in the user_fields and location_fields.
Definition: protocol.hpp:142
immer::array< std::string > locationFields
Fields which may be used to identify a third party location.
Definition: protocol.hpp:132
immer::array< std::string > userFields
Fields which may be used to identify a third party user.
Definition: protocol.hpp:126
immer::array< ProtocolInstance > instances
A list of objects representing independent instances of configuration.
Definition: protocol.hpp:147
static void to_json(json &jo, const FieldType &pod)
Definition: protocol.hpp:31
static void from_json(const json &jo, FieldType &result)
Definition: protocol.hpp:41
static void from_json(const json &jo, ProtocolInstance &result)
Definition: protocol.hpp:96
static void to_json(json &jo, const ProtocolInstance &pod)
Definition: protocol.hpp:82
static void to_json(json &jo, const ThirdPartyProtocol &pod)
Definition: protocol.hpp:157
static void from_json(const json &jo, ThirdPartyProtocol &result)
Definition: protocol.hpp:173