Beat the Kryoflux stream reader into enough shape that it will handle the weird

Kryoflux index markers; refactor it to use Bytes rather than raw streams
(because streams in C++ are terrible).
This commit is contained in:
David Given
2019-04-14 14:35:52 +02:00
parent 64ae92b16f
commit db14642504
9 changed files with 148 additions and 57 deletions

View File

@@ -5,28 +5,6 @@
#include "fluxmap.h"
#include "kryoflux.h"
struct memstreambuf : std::streambuf
{
memstreambuf(const Bytes& bytes)
{
this->setg((char*) bytes.begin(), (char*) bytes.begin(), (char*) bytes.end());
}
};
class memstream : public std::istream
{
public:
memstream(const Bytes& bytes):
std::istream(&_buffer),
_buffer(bytes)
{
rdbuf(&_buffer);
}
private:
memstreambuf _buffer;
};
static Bytes operator + (const Bytes& left, const Bytes& right)
{
Bytes output;
@@ -47,8 +25,7 @@ static Bytes operator * (const Bytes& left, size_t count)
static void test_convert(const Bytes& kryofluxbytes, const Bytes& fluxmapbytes)
{
memstream stream(kryofluxbytes);
std::unique_ptr<Fluxmap> fluxmap = readStream(stream);
std::unique_ptr<Fluxmap> fluxmap = readStream(kryofluxbytes);
if (fluxmap->rawBytes() != fluxmapbytes)
{
@@ -58,7 +35,7 @@ static void test_convert(const Bytes& kryofluxbytes, const Bytes& fluxmapbytes)
hexdump(std::cout, fluxmap->rawBytes());
std::cout << std::endl << "Expected this:" << std::endl;
hexdump(std::cout, fluxmapbytes);
exit(1);
abort();
}
}