#ifndef SERIALIZE_FLOATS_HPP_
#define SERIALIZE_FLOATS_HPP_

#include <Serialize/Base.hpp>

#define DERIVE_REINTERPRET_SERIALIZER(TSource, TIntermediate)\
    template<> struct SerialCodec<TSource> : public ReinterpretingSerialCodec<TSource, TIntermediate> {}

template<typename TSource, typename TIntermediate>
struct ReinterpretingSerialCodec
{
    static constexpr void encode(std::vector<uint8_t> &outBytes, const TSource &obj)
    {
        union
        {
            TSource source;
            TIntermediate intermediate;
        } u;

        u.source = obj;
        serializeInto(outBytes, u.intermediate);
    }

    static constexpr size_t decode(const uint8_t *data, size_t size, TSource &obj)
    {
        union
        {
            TSource source;
            TIntermediate intermediate;
        } u;

        size_t result = deserialize(data, size, u.intermediate);
        obj = u.source;
        return result;
    }
};

DERIVE_REINTERPRET_SERIALIZER(float, uint32_t);
DERIVE_REINTERPRET_SERIALIZER(double, uint64_t);

#endif