Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions include/rfl/capnproto/is_named_type.hpp
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
#ifndef RFL_CAPNPROTO_IS_NAMED_TYPE_HPP_
#define RFL_CAPNPROTO_IS_NAMED_TYPE_HPP_

#include <type_traits>

#include "../parsing/schema/Type.hpp"

namespace rfl::capnproto {

inline bool is_named_type(const parsing::schema::Type& _type) {
return _type.variant_.visit([&](const auto& _v) -> bool {
using T = std::remove_cvref_t<decltype(_v)>;
return std::is_same<T, parsing::schema::Type::Object>() ||
std::is_same<T, parsing::schema::Type::AnyOf>() ||
std::is_same<T, parsing::schema::Type::StringMap>() ||
std::is_same<T, parsing::schema::Type::Literal>();
if constexpr (std::is_same_v<T, parsing::schema::Type::Description> ||
std::is_same_v<T, parsing::schema::Type::Deprecated>) {
return is_named_type(*_v.type_);
} else {
return std::is_same<T, parsing::schema::Type::Object>() ||
std::is_same<T, parsing::schema::Type::AnyOf>() ||
std::is_same<T, parsing::schema::Type::StringMap>() ||
std::is_same<T, parsing::schema::Type::Literal>();
}
});
}

Expand Down
9 changes: 7 additions & 2 deletions src/rfl/avro/to_schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ namespace rfl::avro {
inline bool is_named_type(const parsing::schema::Type& _type) {
return _type.variant_.visit([&](const auto& _v) -> bool {
using T = std::remove_cvref_t<decltype(_v)>;
return std::is_same<T, parsing::schema::Type::Object>() ||
std::is_same<T, parsing::schema::Type::Literal>();
if constexpr (std::is_same_v<T, parsing::schema::Type::Description> ||
std::is_same_v<T, parsing::schema::Type::Deprecated>) {
return is_named_type(*_v.type_);
} else {
return std::is_same<T, parsing::schema::Type::Object>() ||
std::is_same<T, parsing::schema::Type::Literal>();
}
});
}

Expand Down
19 changes: 13 additions & 6 deletions src/rfl/capnproto/to_schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ schema::Type reference_to_capnproto_schema_type(
}
}

inline bool is_literal_type(const parsing::schema::Type& _type) {
return _type.variant_.visit([](const auto& _v) -> bool {
using T = std::remove_cvref_t<decltype(_v)>;
if constexpr (std::is_same_v<T, parsing::schema::Type::Description> ||
std::is_same_v<T, parsing::schema::Type::Deprecated>) {
return is_literal_type(*_v.type_);
} else {
return std::is_same_v<T, parsing::schema::Type::Literal>;
}
});
}

schema::Type string_map_to_capnproto_schema_type(
const parsing::schema::Type::StringMap& _map,
const std::map<std::string, parsing::schema::Type>& _definitions,
Expand All @@ -151,12 +163,7 @@ schema::Type string_map_to_capnproto_schema_type(
if constexpr (std::is_same_v<T, Type::Reference>) {
const auto it = _definitions.find(_value.type_name);
return _cnp_types->enums_.contains(_value.type_name) ||
(it != _definitions.end() &&
it->second.variant_.visit([](const auto& _definition) {
return std::is_same_v<
std::remove_cvref_t<decltype(_definition)>,
parsing::schema::Type::Literal>;
}));
(it != _definitions.end() && is_literal_type(it->second));
} else {
return !std::is_same_v<T, Type::Data> && !std::is_same_v<T, Type::Text> &&
!std::is_same_v<T, Type::List> && !std::is_same_v<T, Type::Map> &&
Expand Down
Loading