#include "tile/base/compression/compression.h"

namespace tile {
TILE_DEFINE_CLASS_DEPENDENCY_REGISTRY(compressor_registry, Compressor);
TILE_DEFINE_CLASS_DEPENDENCY_REGISTRY(decompressor_registry, Decompressor);

TestCompressionOutputStream::TestCompressionOutputStream(std::string *s, std::size_t every_size)
    : buffer_(s),
      every_size_(every_size)
{}

bool
TestCompressionOutputStream::Next(void **data, std::size_t *size) noexcept
{
    if (buffer_->size() < using_bytes_ + every_size_) { buffer_->resize(using_bytes_ + every_size_); }

    *data = internal::RemoveConstPtr(buffer_->data()) + using_bytes_;
    *size = every_size_;

    using_bytes_ += every_size_;
    return true;
}

void
TestCompressionOutputStream::BackUp(std::size_t count) noexcept
{
    using_bytes_ -= count;
}

void
TestCompressionOutputStream::Flush()
{
    buffer_->resize(using_bytes_);
}

}// namespace tile
