mirror of
https://github.com/davidgiven/fluxengine.git
synced 2025-10-31 11:17:01 -07:00
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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user