#ifndef SERIALIZE_DERIVE_HPP_
#define SERIALIZE_DERIVE_HPP_

#include <Serialize/Base.hpp>

#define DERIVE_STRUCT_SERIALIZER_PARTIAL(T, ...) struct SerialCodec<T> {\
    static void encode(std::vector<uint8_t> &outBytes, const T &self)\
    {\
        serializeInto(outBytes, __VA_ARGS__);\
    }\
    static size_t decode(const uint8_t *data, size_t size, T &self)\
    {\
        return deserialize(data, size, __VA_ARGS__);\
    }\
}

#define DERIVE_STRUCT_SERIALIZER(...) template<> DERIVE_STRUCT_SERIALIZER_PARTIAL(__VA_ARGS__)

#define DERIVE_STATIC_CAST_SERIALIZER(TSource, TTarget) template<> struct SerialCodec<TSource> {\
    static void encode(std::vector<uint8_t> &outBytes, const TSource &self)\
    {\
        TTarget u = static_cast<TTarget>(self);\
        serializeInto(outBytes, u);\
    }\
    static size_t decode(const uint8_t *data, size_t size, TSource &self)\
    {\
        TTarget u;\
        size_t result = deserialize(data, size, u);\
        self = static_cast<TSource>(u);\
        return result;\
    }\
}

#endif