#pragma once

#include "BitStream.h"

#include <vector>
#include <iterator>

class BufferBitStream : public BitStream
{
public:
    bool isFinished() const override;

    std::vector<unsigned char> peekNextNBytes(unsigned n) const override;

    std::optional<unsigned char> readNextByte() override;

    void setBuffer(const std::vector<unsigned char>& data);

    void writeByte(unsigned char data, bool checkOverflow = true) override;

    void writeBytes(const std::vector<unsigned char> data) override
    {
        std::copy(data.begin(), data.end(), std::back_inserter(mBuffer));
    }

    const std::vector<unsigned char>& getBuffer() const
    {
        return mBuffer;
    }

    void reset() override
    {
        BitStream::reset();
        mBuffer.clear();
    }

private:
    unsigned mBufferSize{0};
    std::vector<unsigned char> mBuffer;
};
