feat: add initial experimental Twitch Eventsub support (#5837)
Co-authored-by: nerix <nerixdev@outlook.de>
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
boost::json::result_for<{{enum.full_name}}, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<{{enum.full_name}}>, const boost::json::value &jvRoot);
|
||||
@@ -0,0 +1,21 @@
|
||||
boost::json::result_for<{{enum.full_name}}, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<{{enum.full_name}}>, const boost::json::value &jvRoot)
|
||||
{
|
||||
if (!jvRoot.is_string())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeString{"{{enum.full_name}} must be a string"};
|
||||
return boost::system::error_code{129, errorMustBeString};
|
||||
}
|
||||
std::string_view eString(jvRoot.get_string());
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
{%- for constant in enum.constants %}
|
||||
if (eString == "{{constant.json_name}}"sv) {
|
||||
return {{enum.full_name}}::{{constant.name}};
|
||||
}
|
||||
{%- endfor %}
|
||||
|
||||
static const error::ApplicationErrorCategory errorEnumNameDidNotExist{"{{enum.full_name}} did not have a constant that matched this string"};
|
||||
return boost::system::error_code{129, errorEnumNameDidNotExist};
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
return {{field.name}}.error();
|
||||
@@ -0,0 +1,2 @@
|
||||
static const error::ApplicationErrorCategory error_missing_field_{{field.name}}{"Missing required key {{field.json_name}}"};
|
||||
return boost::system::error_code{129, error_missing_field_{{field.name}}};
|
||||
@@ -0,0 +1,15 @@
|
||||
const auto *jv{{field.name}} = root.if_contains("{{field.json_name}}");
|
||||
if (jv{{field.name}} == nullptr)
|
||||
{
|
||||
{% include 'error-missing-field.tmpl' indent content %}
|
||||
}
|
||||
{% if field.tag %}
|
||||
auto {{field.name}} = boost::json::try_value_to<{{field.type_name}}>(*jv{{field.name}}, {{field.tag}}());
|
||||
{% else %}
|
||||
auto {{field.name}} = boost::json::try_value_to<{{field.type_name}}>(*jv{{field.name}});
|
||||
{% endif %}
|
||||
if ({{field.name}}.has_error())
|
||||
{
|
||||
{% include 'error-failed-to-deserialize.tmpl' indent content %}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
assert(false && "OPTIONAL VECTOR FIELD UNIMPLEMENTED");
|
||||
@@ -0,0 +1,27 @@
|
||||
std::optional<{{field.type_name}}> {{field.name}} = std::nullopt;
|
||||
const auto *jv{{field.name}} = root.if_contains("{{field.json_name}}");
|
||||
if (jv{{field.name}} != nullptr && !jv{{field.name}}->is_null())
|
||||
{
|
||||
{% if field.tag %}
|
||||
auto t{{field.name}} = boost::json::try_value_to<{{field.type_name}}>(*jv{{field.name}}, {{field.tag}}());
|
||||
{% else %}
|
||||
auto t{{field.name}} = boost::json::try_value_to<{{field.type_name}}>(*jv{{field.name}});
|
||||
{% endif %}
|
||||
{% if field.dont_fail_on_deserialization %}
|
||||
if (t{{field.name}}.has_error())
|
||||
{
|
||||
// TODO: report error in some way?
|
||||
}
|
||||
else
|
||||
{
|
||||
{{field.name}} = t{{field.name}}.value();
|
||||
}
|
||||
{% else %}
|
||||
if (t{{field.name}}.has_error())
|
||||
{
|
||||
return t{{field.name}}.error();
|
||||
}
|
||||
{{field.name}} = std::move(t{{field.name}}.value());
|
||||
{% endif %}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
{% if field.tag -%}
|
||||
static_assert(false && "JSON tag support is not implemented for vectors");
|
||||
{%- endif %}
|
||||
const auto *jv{{field.name}} = root.if_contains("{{field.json_name}}");
|
||||
if (jv{{field.name}} == nullptr)
|
||||
{
|
||||
{% include 'error-missing-field.tmpl' indent content %}
|
||||
}
|
||||
const auto {{field.name}} = boost::json::try_value_to<std::vector<{{field.type_name}}>>(*jv{{field.name}});
|
||||
if ({{field.name}}.has_error())
|
||||
{
|
||||
{% include 'error-failed-to-deserialize.tmpl' indent content %}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
.{{field.name}} = std::move({{field.name}}.value()),
|
||||
@@ -0,0 +1 @@
|
||||
assert(false && "OPTIONAL VECTOR INITIALIZER UNIMPLEMENTED");
|
||||
@@ -0,0 +1 @@
|
||||
.{{field.name}} = std::move({{field.name}}),
|
||||
@@ -0,0 +1 @@
|
||||
.{{field.name}} = {{field.name}}.value(),
|
||||
@@ -0,0 +1,2 @@
|
||||
boost::json::result_for<{{struct.full_name}}, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<{{struct.full_name}}>, const boost::json::value &jvRoot);
|
||||
@@ -0,0 +1,58 @@
|
||||
boost::json::result_for<{{struct.full_name}}, boost::json::value>::type tag_invoke(
|
||||
boost::json::try_value_to_tag<{{struct.full_name}}>, const boost::json::value &jvRoot)
|
||||
{
|
||||
{% if struct.inner_root %}
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{"{{struct.full_name}} must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &outerRoot = jvRoot.get_object();
|
||||
|
||||
const auto *jvInnerRoot = outerRoot.if_contains("{{struct.inner_root}}");
|
||||
if (jvInnerRoot == nullptr)
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMissing{"{{struct.full_name}}'s key {{struct.inner_root}} is missing"};
|
||||
return boost::system::error_code{129, errorMissing};
|
||||
}
|
||||
if (!jvInnerRoot->is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{"{{struct.full_name}}'s {{struct.inner_root}} must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvInnerRoot->get_object();
|
||||
{% else %}
|
||||
if (!jvRoot.is_object())
|
||||
{
|
||||
static const error::ApplicationErrorCategory errorMustBeObject{"{{struct.full_name}} must be an object"};
|
||||
return boost::system::error_code{129, errorMustBeObject};
|
||||
}
|
||||
const auto &root = jvRoot.get_object();
|
||||
{% endif %}
|
||||
|
||||
{% for field in struct.members %}
|
||||
{% if field.member_type == MemberType.BASIC -%}
|
||||
{% include 'field-basic.tmpl' indent content %}
|
||||
{%- elif field.member_type == MemberType.VECTOR -%}
|
||||
{% include 'field-vector.tmpl' indent content %}
|
||||
{%- elif field.member_type == MemberType.OPTIONAL -%}
|
||||
{% include 'field-optional.tmpl' indent content %}
|
||||
{%- elif field.member_type == MemberType.OPTIONAL_VECTOR -%}
|
||||
{% include 'field-optional-vector.tmpl' indent content %}
|
||||
{%- endif -%}
|
||||
{% endfor %}
|
||||
|
||||
return {{struct.full_name}}{
|
||||
{%- for field in struct.members %}
|
||||
{% if field.member_type == MemberType.BASIC -%}
|
||||
{% include 'initializer-basic.tmpl' indent content %}
|
||||
{%- elif field.member_type == MemberType.VECTOR -%}
|
||||
{% include 'initializer-vector.tmpl' indent content %}
|
||||
{%- elif field.member_type == MemberType.OPTIONAL -%}
|
||||
{% include 'initializer-optional.tmpl' indent content %}
|
||||
{%- elif field.member_type == MemberType.OPTIONAL_VECTOR -%}
|
||||
{% include 'initializer-optional-vector.tmpl' indent content %}
|
||||
{%- endif -%}
|
||||
{% endfor %}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user