niXman / yas

Yet Another Serialization
731 stars 95 forks source link

When there are more fields than 19, there is a bug in deserialization #148

Closed xushengbo closed 1 year ago

xushengbo commented 1 year ago
struct Type
{

    int a;
    double b;
    int c;
    double d;           
    int e;
    int f;
    double g;
    int h;
    int i;
    double j;
    bool k;
    int l;
    int m;

    double n;
    int o;
    double p;
    int q;
    double r;
    int s;
    int t;
    int u;
    double v;
    int w;
    int x;

    template<typename Ar>
    void serialize(Ar& ar)
    {
        ar& YAS_OBJECT("type", a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x);
    }
};

int main() {

    Type t1, t2;
    constexpr std::size_t flags = yas::mem | yas::binary;
    auto buf  = yas::save<flags>(t1);

    yas::load<flags>(buf, t2);

}
error C2243:  “std::tuple<yas::value<int &>,yas::value<double &>,yas::value<int &>,yas::value<double &>,yas::value<int &>,yas::value<int &>,yas::value<double &>,yas::value<int &>,yas::value<int &>,yas::value<double &>,yas::value<bool &>,yas::value<int &>,yas::value<int &>,yas::value<double &>,yas::value<int &>,yas::value<double &>,yas::value<int &>,yas::value<double &>,yas::value<int &>,yas::value<int &>,yas::value<int &>,yas::value<double &>,yas::value<int &>,yas::value<int &>> *” to “std::tuple<> &”

please provide the correct compiler error message.

niXman commented 1 year ago

In any case, I think you should set the required number of YAS_OBJECT members for your project: https://github.com/niXman/yas/blob/master/include/yas/detail/config/config.hpp#L63C37-L63C37

xushengbo commented 1 year ago

Thank you for your response, I have solved the problem according to your suggestion, thank you again.