-
Notifications
You must be signed in to change notification settings - Fork 266
Expand file tree
/
Copy pathtypes.cpp.j2
More file actions
63 lines (54 loc) · 1.91 KB
/
Copy pathtypes.cpp.j2
File metadata and controls
63 lines (54 loc) · 1.91 KB
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
// Generated by `make api-generate`. Do not edit.
#include "tgbot/Json.h"
#include "tgbot/Types.h"
#include <stdexcept>
namespace TgBot {
{% for object in objects %}
{% for constant in object.constants %}
const std::string {{ object.name }}::{{ constant.name }} = "{{ constant.value }}";
{% endfor %}
{% if object.constants %}
{% endif %}
{% for enum in object.enums %}
void from_json(const nlohmann::json& json, {{ object.name }}::{{ enum.name }}& value) {
const auto text = json.get<std::string>();
{% for enum_value in enum.values %}
if (text == "{{ enum_value.value }}") {
value = {{ object.name }}::{{ enum.name }}::{{ enum_value.name }};
return;
}
{% endfor %}
throw std::invalid_argument("Unknown {{ object.name }}.{{ enum.name }} value: " + text);
}
void to_json(nlohmann::json& json, const {{ object.name }}::{{ enum.name }}& value) {
switch (value) {
{% for enum_value in enum.values %}
case {{ object.name }}::{{ enum.name }}::{{ enum_value.name }}:
json = "{{ enum_value.value }}";
return;
{% endfor %}
}
throw std::invalid_argument("Unknown {{ object.name }}.{{ enum.name }} value");
}
{% endfor %}
void from_json(const nlohmann::json& json, {{ object.name }}& value) {
{% if object.union_members %}
Json::decode(json, value.value);
{% else %}
{% for field in object.fields %}
Json::{{ "readRequiredField" if field.required else "readOptionalField" }}(json, "{{ field.wire_name }}", value.{{ field.cpp_name }});
{% endfor %}
{% endif %}
}
void to_json(nlohmann::json& json, const {{ object.name }}& value) {
{% if object.union_members %}
json = Json::encode(value.value);
{% else %}
json = nlohmann::json::object();
{% for field in object.fields %}
Json::{{ "writeRequiredField" if field.required else "writeOptionalField" }}(json, "{{ field.wire_name }}", value.{{ field.cpp_name }});
{% endfor %}
{% endif %}
}
{% endfor %}
} // namespace TgBot