morganstanley/binlog

T[N] like fields are not supported for struct tag

Closed this issue · 3 comments

fdrex commented

The Problem:

Suppose you have a struct like:

struct ABC {
  int a;
  short b[10];
  char c[12][2];
};

When you do

MSERIALIZE_MAKE_STRUCT_TAG(ABC, a, b, c);

There will be an error complaining you cann't use a T[] as return type in serializable_member_type.

The Fix:

Add the following overloads to make_struct_tag.hpp

template<typename T, typename E, int N>
auto serializable_member_type(E(T::*)[N]) -> std::vector<E>;

template<typename T, typename E, int N, int M>
auto serializable_member_type(E(T::*)[N][M]) -> std::vector<std::vector<E>>;

template<typename T, typename E, int N, int M, int K>
auto serializable_member_type(E(T::*)[N][M][K]) -> std::vector<std::vector<std::vector<E>>>;

In this way, the fields will be correctly mathed as a (possibly nested) Sequence.

I have tested with tag/serialization/deserialization/visit, they all seems to be ok.

fdrex commented

T[N] are quite common types, I think they should be supported as a first citizen. If there's something wrong with my understanding or usage, please point it out. Thanks.

Thanks for the detailed report. Please see: #72

fdrex commented

Your patch is indeed a better solution.