Skip to content

Commit

Permalink
remove one_of_t[struct_pb]
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbgan committed May 8, 2024
1 parent bda33a4 commit 0482628
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 49 deletions.
3 changes: 0 additions & 3 deletions iguana/pb_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ inline void from_pb_impl(T& val, std::string_view& pb_str, uint32_t field_no) {
else if constexpr (optional_v<T>) {
from_pb_impl(val.emplace(), pb_str);
}
else if constexpr (is_one_of_v<T>) {
from_pb_impl(val.value, pb_str);
}
else {
static_assert(!sizeof(T), "err");
}
Expand Down
26 changes: 1 addition & 25 deletions iguana/pb_util.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,6 @@ enum class WireType : uint32_t {
Unknown
};

template <size_t Idx, typename V>
struct one_of_t {
static constexpr bool is_one_of_v = true;
using value_type = std::optional<
std::remove_reference_t<decltype(std::get<Idx>(std::declval<V>()))>>;
value_type value;
};

namespace detail {
template <typename T>
constexpr bool is_fixed_v =
Expand All @@ -46,16 +38,6 @@ template <typename T>
constexpr bool is_signed_varint_v =
std::is_same_v<T, sint32_t> || std::is_same_v<T, sint64_t>;

template <typename Type, typename = void>
struct is_one_of_t : std::false_type {};

template <typename T>
struct is_one_of_t<T, std::void_t<decltype(T::is_one_of_v)>> : std::true_type {
};

template <typename T>
constexpr bool is_one_of_v = is_one_of_t<T>::value;

template <typename T>
constexpr inline WireType get_wire_type() {
if constexpr (std::is_integral_v<T> || is_signed_varint_v<T> ||
Expand All @@ -78,7 +60,7 @@ constexpr inline WireType get_wire_type() {
is_map_container<T>::value) {
return WireType::LengthDelimeted;
}
else if constexpr (optional_v<T> || is_one_of_v<T>) {
else if constexpr (optional_v<T>) {
return get_wire_type<typename T::value_type>();
}
else {
Expand Down Expand Up @@ -421,9 +403,6 @@ inline size_t pb_key_value_size(T&& t) {
}
return pb_key_value_size<key_size>(*t);
}
else if constexpr (is_one_of_v<value_type>) {
return pb_key_value_size<key_size>(t.value);
}
else if constexpr (std::is_same_v<value_type, std::string> ||
std::is_same_v<value_type, std::string_view>) {
if (t.size() == 0) {
Expand Down Expand Up @@ -471,9 +450,6 @@ inline size_t pb_value_size(T&& t) {
}
return pb_value_size(*t);
}
else if constexpr (is_one_of_v<value_type>) {
return pb_value_size(t.value);
}
else {
return pb_key_value_size<0>(t);
}
Expand Down
3 changes: 0 additions & 3 deletions iguana/pb_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,6 @@ inline void to_pb_impl(Type&& t, Stream& out) {
}
to_pb_impl<key, omit_default_val>(*t, out);
}
else if constexpr (is_one_of_v<T>) {
to_pb_impl<key, omit_default_val>(t.value, out);
}
else if constexpr (std::is_same_v<T, std::string> ||
std::is_same_v<T, std::string_view>) {
if constexpr (omit_default_val) {
Expand Down
18 changes: 0 additions & 18 deletions test/test_pb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,6 @@ struct test_pb_st6 {
};
REFLECTION(test_pb_st6, x, y);

using Variant1 = std::variant<std::string, int>;
struct test_pb_st7 {
iguana::one_of_t<0, Variant1> x;
iguana::one_of_t<1, Variant1> y;
};
REFLECTION(test_pb_st7, x, y);

struct pair_t {
int x;
int y;
Expand Down Expand Up @@ -256,17 +249,6 @@ TEST_CASE("test struct_pb") {
iguana::from_pb(st2, str);
CHECK(st1.y == st2.y);
}
{
// variant
test_pb_st7 st1{{"test"}};
std::string str;
iguana::to_pb(st1, str);
CHECK(str.size() == iguana::detail::pb_key_value_size<0>(st1));

test_pb_st7 st2;
iguana::from_pb(st2, str);
CHECK(st1.x.value == st2.x.value);
}
{
// sub nested objects
nest1 v{"Hi", {1, false, {3}}, 5}, v2{};
Expand Down

0 comments on commit 0482628

Please sign in to comment.