0

I'm using "msgpack" to serialize my messages. There is a customized type that was defined in a 3rd party lib's header, I can NOT modify the include file, i.e. I should NOT add a MSGPACK_DEFINE into the declare of this class.

But I know that it is a int32_t indeed, and it also offers a getter method named as<int32_t>(); like the following:

class GlobalCustomizedType_t {
    template <typename T>
    T as() const { return static_cast<T>( _data ); };
protected:
    int32_t _data;
};

Now I need to serialize my message struct that has a member of type GlobalCustomizedType_t with msgpack. Obviously I can't directly add a macro into my message struct, like this:

struct MyMessage_t {
    GlobalCustomizedType_t _glob;

    MSGPACK_DEFINE( _glob );
};

I have tried it like this:

struct MyMessage_t {
    GlobalCustomizedType_t _glob;

    MSGPACK_DEFINE( _glob.as<int32_t> );
};

But it still can't work.

Would anyone please to help me? thx!

Leon
  • 1,489
  • 1
  • 12
  • 31
  • Have you checked [non-intrusive approach](https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_adaptor#non-intrusive-approach) docs? (there is an example there) – dewaffled Aug 12 '23 at 13:55

0 Answers0