#ifndef BUFFER_H
#define BUFFER_H

#include <cstring>

template<int N>
class Buffer {
    char data[N];
    int length = 0;

public:

    template<typename T>
    Buffer& add(const T& t) {
        int bytes = N - length;
        if(bytes > static_cast<int> (sizeof (T))) {
            bytes = sizeof (T);
        }
        memcpy(data + length, &t, bytes);
        length += bytes;
        return *this;
    }

    int getLength() const {
        return length;
    }

    operator const char*() const {
        return data;
    }
};

#endif