fraillt/bitsery

Custom Extension

hanusek opened this issue · 1 comments

Hello.
I have a problem with my own extension.
I am trying to do something like that based on.

Code:

namespace bitsery {
    namespace traits {
        template<typename T>
        struct ExtensionTraits<AuthProtocol::MyExtension, T> {
            using TValue = void;
            static constexpr bool SupportValueOverload = false;
            static constexpr bool SupportObjectOverload = true;
            static constexpr bool SupportLambdaOverload = false;
        };
    }
}

namespace AuthProtocol 
{
    struct Text4b
    {
      uint32_t content_size{0};
      std::string content;
      static constexpr uint32_t MaxSize = std::numeric_limits<uint32_t>::max();
     };
     
    class MyExtension 
    {
        public:
            template<typename Ser, typename T, typename Fnc>
            void serialize(Ser& ser, const T& obj, Fnc&& ) const {
                /// TODO: code
            }

            template<typename Des, typename T, typename Fnc>
            void deserialize(Des& des, T& obj, Fnc&& ) const {
                /// TODO: code
            }
     };

   struct OtherStruct
   {
       Text4b text;

        template <typename S>
        void serialize(S &s)
        {
            s.ext(text, MyExtension{});
         }
   };
}

Error:

243:70: error: static assertion failed: Please define ExtensionTraits
  243 |             static_assert(details::IsExtensionTraitsDefined<Ext, T>::value, "Please define ExtensionTraits");
      |                                                                      ^~~~~
/home/mhanusek/.conan/data/bitsery/5.2.2/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/bitsery/deserializer.h:243:70: note: ‘std::integral_constant<bool, false>::value’ evaluates to false
/home/mhanusek/.conan/data/bitsery/5.2.2/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/bitsery/deserializer.h:244:59: error: static assertion failed: extension doesn't support overload with `object`
  244 |             static_assert(traits::ExtensionTraits<Ext,T>::SupportObjectOverload,
      |                                                           ^~~~~~~~~~~~~~~~~~~~~
/home/mhanusek/.conan/data/bitsery/5.2.2/_/_/package/5ab84d6acfe1f23c4fae0ab88f26e3a396351ac9/include/bitsery/deserializer.h:244:59: note: ‘bitsery::traits::ExtensionTraits<AuthProtocol::MyExtension, AuthProtocol::Text4b>::SupportObjectOverload’ evaluates to false

@fraillt Can you help me?

Maybe you need to forward declare your class?
Try putting this before ExtensionTraits specialization:

namespace AuthProtocol {
  class MyExtension;
}