#ifndef SERIALIZE_STRING_HPP_
#define SERIALIZE_STRING_HPP_

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

template<>
struct SerialCodec<std::string>
{
    static void encode(std::vector<uint8_t> &outBytes, const std::string &str)
    {
        outBytes.insert(outBytes.end(), (uint8_t*) str.c_str(), (uint8_t*) str.c_str() + str.size() + 1);
    }

    static size_t decode(const uint8_t *data, size_t size, std::string &str)
    {
        const uint8_t *p;
        const uint8_t *end = data + size;
        for (p=data; p<end && *p!=0; p++);
        if (p == end) return 0;
        str = std::string((char*) data);

        return str.size()+1;
    }
};

#endif