#ifndef SERIALIZE_POINTERS_HPP_
#define SERIALIZE_POINTERS_HPP_

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

template<typename T>
struct SerialCodec<std::shared_ptr<T>>
{
    static void encode(std::vector<uint8_t> &outBytes, const std::shared_ptr<T> &p)
    {
        serializeInto(outBytes, *p);
    }

    static size_t decode(const uint8_t *data, size_t size, std::shared_ptr<T> &p)
    {
        p = std::make_shared<T>();
        return deserialize(data, size, *p);
    }
};

template<typename T>
struct SerialCodec<std::unique_ptr<T>>
{
    static void encode(std::vector<uint8_t> &outBytes, const std::unique_ptr<T> &p)
    {
        serializeInto(outBytes, *p);
    }

    static size_t decode(const uint8_t *data, size_t size, std::unique_ptr<T> &p)
    {
        p = std::make_unique<T>();
        return deserialize(data, size, *p);
    }
};

#endif