This commit is contained in:
parent
e7ca1d08e9
commit
8019371d46
1 changed files with 25 additions and 59 deletions
|
@ -30,77 +30,43 @@ struct Body {
|
||||||
|
|
||||||
namespace type {
|
namespace type {
|
||||||
|
|
||||||
struct Chat {
|
template <typename T>
|
||||||
static constexpr auto TryParse(std::string_view value) -> std::optional<Chat> {
|
struct TypeImpl {
|
||||||
return value == "chat" ? std::optional{Chat{}} : std::nullopt;
|
static constexpr auto TryParse(std::string_view value) -> std::optional<T> {
|
||||||
|
return value == T::kName ? std::optional{T{}} : std::nullopt;
|
||||||
}
|
}
|
||||||
friend constexpr auto ToString(const Chat&) -> std::string {
|
friend constexpr auto ToString(const T&) -> std::string {
|
||||||
return "chat";
|
return T::kName;
|
||||||
}
|
}
|
||||||
constexpr auto operator==(const Chat&) const -> bool {
|
friend constexpr auto operator==(const T&, const T&) -> bool {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
static constexpr auto kChat = Chat{};
|
struct Chat : TypeImpl<Chat> {
|
||||||
|
static constexpr auto kName = "chat";
|
||||||
|
} constexpr kChat{};
|
||||||
|
|
||||||
struct Error {
|
struct Error : TypeImpl<Error> {
|
||||||
static constexpr auto TryParse(std::string_view value) -> std::optional<Error> {
|
static constexpr auto kName = "error";
|
||||||
return value == "error" ? std::optional{Error{}} : std::nullopt;
|
} constexpr kError{};
|
||||||
}
|
|
||||||
friend constexpr auto ToString(const Error&) -> std::string {
|
|
||||||
return "error";
|
|
||||||
}
|
|
||||||
constexpr auto operator==(const Error&) const -> bool {
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
static constexpr auto kError = Error{};
|
struct GroupChat : TypeImpl<GroupChat> {
|
||||||
|
static constexpr auto kName = "groupchat";
|
||||||
|
} constexpr kGroupChat{};
|
||||||
|
|
||||||
struct GroupChat {
|
struct Headline : TypeImpl<Headline> {
|
||||||
static constexpr auto TryParse(std::string_view value) -> std::optional<GroupChat> {
|
static constexpr auto kName = "headline";
|
||||||
return value == "groupchat" ? std::optional{GroupChat{}} : std::nullopt;
|
} constexpr kHeadline{};
|
||||||
}
|
|
||||||
friend constexpr auto ToString(const GroupChat&) -> std::string {
|
|
||||||
return "groupchat";
|
|
||||||
}
|
|
||||||
constexpr auto operator==(const GroupChat&) const -> bool {
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
static constexpr auto kGroupChat = GroupChat{};
|
struct Normal : TypeImpl<Normal> {
|
||||||
|
static constexpr auto kName = "normal";
|
||||||
struct Headline {
|
|
||||||
static constexpr auto TryParse(std::string_view value) -> std::optional<Headline> {
|
|
||||||
return value == "headline" ? std::optional{Headline{}} : std::nullopt;
|
|
||||||
}
|
|
||||||
friend constexpr auto ToString(const Headline&) -> std::string {
|
|
||||||
return "headline";
|
|
||||||
}
|
|
||||||
constexpr auto operator==(const Headline&) const -> bool {
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
static constexpr auto kHeadline = Headline{};
|
|
||||||
|
|
||||||
struct Normal {
|
|
||||||
static constexpr auto Parse(std::string_view value) -> Normal {
|
static constexpr auto Parse(std::string_view value) -> Normal {
|
||||||
return value == "normal" ? Normal{}
|
return value == kName ? Normal{}
|
||||||
: throw std::runtime_error(
|
: throw std::runtime_error(
|
||||||
std::format(R"(message::type::Normal Parsing error: [ expected "normal" but "{}" found ])", value));
|
std::format(R"(message::type::Normal Parsing error: [ expected "normal" but "{}" found ])", value));
|
||||||
}
|
}
|
||||||
friend constexpr auto ToString(const Normal&) -> std::string {
|
} constexpr kNormal;
|
||||||
return "normal";
|
|
||||||
}
|
|
||||||
constexpr auto operator==(const Normal&) const -> bool {
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
static constexpr auto kNormal = Normal{};
|
|
||||||
|
|
||||||
} // namespace type
|
} // namespace type
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue