Skip to content

Commit e791416

Browse files
committed
Address build issues and comments
1 parent e17c060 commit e791416

4 files changed

Lines changed: 16 additions & 10 deletions

File tree

include/rfl/Deprecated.hpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ struct Deprecated {
4141

4242
Deprecated(const Deprecated& _field) = default;
4343

44-
template <class U>
44+
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
45+
bool>::type = true>
4546
Deprecated(const Deprecated<_deprecation_message, _description, U>& _field)
4647
: value_(_field.get()) {}
4748

48-
template <class U>
49+
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
50+
bool>::type = true>
4951
Deprecated(Deprecated<_deprecation_message, _description, U>&& _field)
50-
: value_(_field.get()) {}
52+
: value_(std::move(_field.value_)) {}
5153

5254
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
5355
bool>::type = true>
@@ -57,11 +59,6 @@ struct Deprecated {
5759
bool>::type = true>
5860
Deprecated(U&& _value) noexcept : value_(std::forward<U>(_value)) {}
5961

60-
template <class U, typename std::enable_if<std::is_convertible_v<U, Type>,
61-
bool>::type = true>
62-
Deprecated(const Deprecated<_deprecation_message, _description, U>& _field)
63-
: value_(_field.value()) {}
64-
6562
/// Assigns the underlying object to its default value.
6663
template <class U = Type,
6764
typename std::enable_if<std::is_default_constructible_v<U>,
@@ -132,7 +129,7 @@ struct Deprecated {
132129
/// Assigns the underlying object.
133130
template <class U>
134131
auto& operator=(Deprecated<_deprecation_message, _description, U>&& _field) {
135-
value_ = std::forward<T>(_field.value_);
132+
value_ = std::move(_field.value_);
136133
return *this;
137134
}
138135

src/rfl/avro/to_schema.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ schema::Type type_to_avro_schema_type(
8080
}
8181
return schema::Type{.value = any_of};
8282

83+
} else if constexpr (std::is_same<T, Type::Deprecated>()) {
84+
return type_to_avro_schema_type(*_t.type_, _definitions, _already_known,
85+
_num_unnamed);
86+
8387
} else if constexpr (std::is_same<T, Type::Description>()) {
8488
// TODO: Return descriptions
8589
return type_to_avro_schema_type(*_t.type_, _definitions, _already_known,

src/rfl/capnproto/to_schema.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ schema::Type type_to_capnproto_schema_type(
179179
return any_of_to_capnproto_schema_type(_t, _definitions, _parent,
180180
_cnp_types);
181181

182+
} else if constexpr (std::is_same<T, Type::Deprecated>()) {
183+
return type_to_capnproto_schema_type(*_t.type_, _definitions, _parent,
184+
_cnp_types);
185+
182186
} else if constexpr (std::is_same<T, Type::Description>()) {
183187
return type_to_capnproto_schema_type(*_t.type_, _definitions, _parent,
184188
_cnp_types);

tests/json/test_json_schema_deprecation.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,10 @@ TEST(json, test_deprecated_optional_field) {
5555
}
5656

5757
TEST(json, test_deprecated_read_write) {
58+
const auto expected = R"({"old_name":"legacy","new_name":"current"})";
5859
const auto obj =
5960
DeprecatedBasicField{.old_name = "legacy", .new_name = "current"};
60-
write_and_read(obj);
61+
write_and_read(obj, expected);
6162
}
6263

6364
} // namespace test_deprecated_schema

0 commit comments

Comments
 (0)