]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Revert "Merge pull request #33673 from cbodley/wip-denc-enum" 33832/head
authorSage Weil <sage@redhat.com>
Tue, 10 Mar 2020 03:23:47 +0000 (22:23 -0500)
committerSage Weil <sage@redhat.com>
Tue, 10 Mar 2020 03:23:47 +0000 (22:23 -0500)
This reverts commit 1041092696c2e3c9ee4e32b764ead06f5bc1f694, reversing
changes made to c2f584f32a9619b39d53178c2327dc26b3a2a27c.

This changed the encoding for certain types.

Signed-off-by: Sage Weil <sage@redhat.com>
src/include/denc.h
src/test/test_denc.cc

index b837f74e24aabbe0dd6458fa9633d979e9cf3fed..adb93ad16a1afbd2b37b4497652c4047b2246178 100644 (file)
@@ -268,7 +268,17 @@ template<typename T> int DencDumper<T>::i = 0;
 namespace _denc {
 template<typename T, typename... Us>
 inline constexpr bool is_any_of = (... || std::is_same_v<T, Us>);
-} // namespace _denc
+
+template<typename T, typename=void> struct underlying_type {
+  using type = T;
+};
+template<typename T>
+struct underlying_type<T, std::enable_if_t<std::is_enum_v<T>>> {
+  using type = std::underlying_type_t<T>;
+};
+template<typename T>
+using underlying_type_t = typename underlying_type<T>::type;
+}
 
 template<class It>
 struct is_const_iterator
@@ -297,12 +307,11 @@ get_pos_add(It& i) {
   return *reinterpret_cast<T*>(i.get_pos_add(sizeof(T)));
 }
 
-// network-order integer encoding
 template<typename T>
 struct denc_traits<
   T,
   std::enable_if_t<
-    _denc::is_any_of<T,
+    _denc::is_any_of<_denc::underlying_type_t<T>,
                     ceph_le64, ceph_le32, ceph_le16, uint8_t
 #ifndef _CHAR_IS_SIGNED
                       , int8_t
@@ -402,44 +411,6 @@ struct denc_traits<T, std::enable_if_t<!std::is_void_v<_denc::ExtType_t<T>>>>
   }
 };
 
-
-// enum
-//
-template<typename T>
-struct denc_traits<T, std::enable_if_t<std::is_enum_v<T>>>
-{
-  static constexpr bool supported = true;
-  static constexpr bool featured = false;
-  static constexpr bool bounded = true;
-  static constexpr bool need_contiguous = false;
-
-  using enum_type = T;
-  using underlying_type = std::underlying_type_t<enum_type>;
-  using base_traits = denc_traits<underlying_type>;
-
-  static void bound_encode(const T &o, size_t& p, uint64_t f=0) {
-    base_traits::bound_encode(static_cast<underlying_type>(o), p, f);
-  }
-  template<class It>
-  static std::enable_if_t<!is_const_iterator_v<It>>
-  encode(const T &o, It& p, uint64_t f=0) {
-    base_traits::encode(static_cast<underlying_type>(o), p, f);
-  }
-  template<class It>
-  static std::enable_if_t<is_const_iterator_v<It>>
-  decode(T& o, It& p, uint64_t f=0) {
-    underlying_type v;
-    base_traits::decode(v, p, f);
-    o = static_cast<enum_type>(v);
-  }
-  static void decode(T& o, ceph::buffer::list::const_iterator &p) {
-    underlying_type v;
-    base_traits::decode(v, p);
-    o = static_cast<enum_type>(v);
-  }
-};
-
-
 // varint
 //
 // high bit of each byte indicates another byte follows.
index 7df181d9e67b16bf56690523fb7b6a911901af77..0924ee4eda2c8fa65462bc25fc2405db2299166d 100644 (file)
@@ -180,28 +180,6 @@ TEST(denc, string)
   test_denc(c);
 }
 
-TEST(denc, enum_class)
-{
-  enum class enum_class_8 : int8_t { value };
-  test_denc(enum_class_8::value);
-  enum class enum_class_u8 : uint8_t { value };
-  test_denc(enum_class_u8::value);
-  enum class enum_class_16 : int16_t { value };
-  test_denc(enum_class_16::value);
-  enum class enum_class_u16 : uint16_t { value };
-  test_denc(enum_class_u16::value);
-  enum class enum_class_32 : int32_t { value };
-  test_denc(enum_class_32::value);
-  enum class enum_class_u32 : uint32_t { value };
-  test_denc(enum_class_u32::value);
-  enum class enum_class_64 : int64_t { value };
-  test_denc(enum_class_64::value);
-  enum class enum_class_u64 : uint64_t { value };
-  test_denc(enum_class_u64::value);
-  enum class enum_class { value };
-  test_denc(enum_class::value);
-}
-
 struct legacy_t {
   int32_t a = 1;
   void encode(bufferlist& bl) const {