#ifndef SERIALIZE_PLAIN_HPP_
#define SERIALIZE_PLAIN_HPP_

#include <Serialize/Base.hpp>
#include <Utilities/Utilities.hpp>

#define PLAIN_SERIALIZABLE(T) template<> struct SerialCodec<T> : public PlainSerialCodec<T> {}

template<typename TPlain>
struct PlainSerialCodec
{
    static void encode(std::vector<uint8_t> &outBytes, const TPlain &obj)
    {
        const uint8_t *bytes = (const uint8_t*) (const void*) &obj;
        outBytes.insert(outBytes.end(), bytes, bytes + sizeof(TPlain));
    }

    static size_t decode(const uint8_t *data, size_t size, TPlain &obj)
    {
        if (size < sizeof(TPlain))
        {
            return 0;
        }

        std::memcpy(&obj, data, sizeof(TPlain));
        return sizeof(TPlain);
    }
};

#endif