Skip to content

fill buffer with data not from file but of a known format #41

Description

@lain3d

Just as a test I've done this:

struct membuf : std::streambuf
{
    membuf(char* begin, char* end) {
        this->setg(begin, begin, end);
    }
};

class FileFactory final : public alure::FileIOFactory {
private:
    membuf buf;
public:
    FileFactory(membuf &bufin) : buf(bufin)
    {
        std::cout << "hello" << std::endl;
    }

    alure::UniquePtr<std::istream> openFile(const alure::String &name) noexcept override
    {
        auto stream = alure::MakeUnique<std::istream>(&buf);
        if (stream->fail()) {
            std::cout << "failed" << std::endl;
        }
        return std::move(stream); 
    }
};

In my main function I have:
membuf sbuf(existing_buff, existing_buff + sz);
alure::FileIOFactory::set(alure::MakeUnique<FileFactory>(sbuf));

When I run my test I get:
Failed to rewind file for the next decoder factory

This is just a test, I was planning to pass in a map of id,buf in the constructor to the factory if I got this to work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions