I have a method deserialize
taking a reference to opened std::istream
where normally I pass in an std::ifstream
opened with std::ios::binary
option.
Now I would like to test it with some binary (hex) literals but I do not know how to feed that data into the std::istream
.
I tried something similar like in this answer
struct membuf : std::streambuf
{
membuf(char* begin, char* end)
{
this->setg(begin, begin, end);
}
};
int main()
{
char buffer[] = "0a0b0c0d000000480000000000420410000";
membuf sbuf(buffer, buffer + sizeof(buffer) - 1);
std::istream in(&sbuf);
deserialize(in);
}
Which fails because that data is not read/fed as binary.
How can I do it?