Skip to content

Commit

Permalink
Minor code beautifications
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzicheng1987 committed Dec 28, 2024
1 parent 886017c commit eddff20
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/rfl/capnproto/to_schema.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,18 @@ namespace rfl::capnproto {
std::string to_string_representation(
const parsing::schema::Definition& internal_schema);

/// This ensures that the schema is only generated once.
template <class T, class... Ps>
struct SchemaHolder {
rfl::Result<Schema<T>> schema_;
static SchemaHolder<T, Ps...> make() noexcept {
const auto internal_schema =
parsing::schema::make<Reader, Writer, T,
Processors<SnakeCaseToCamelCase, Ps...>>();
const auto str = to_string_representation(internal_schema);
return SchemaHolder<T, Ps...>{Schema<T>::from_string(str)};
}

rfl::Result<Schema<T>> schema_;
};

template <class T, class... Ps>
Expand Down

0 comments on commit eddff20

Please sign in to comment.