return with 0xff in <stream>::underflow()

Hi.

I am trying to implement a stream to decode base64 on-the-fly from another stream. To do this I created a new class derived from std::basic_streambuf<char, std::char_traits<char> > and everything seems to work except one thing.

In the onderflow() function I have to return the first byte of the buffer with the decoded payload. But the decoded payload could contain the byte 0xff. If I return this character, the stream assumes the end of the stream because 0xff = EOF.

Most of the examples in the web use this to change the value, if it is equal to EOF.

return std::char_traits<char>::not_eof(data_buf_[0]);

But this seems to change the return value and the stream returns wrong data!?

What is the right strategy for this problem?

Thank in advance for help!
Jonny
A night of sleep solved the problem. In my special case I have to cast the char to unsigned char and everything works as supposed.

return std::char_traits<char>::not_eof((unsigned char) data_buf_[0]);
Last edited on
Topic archived. No new replies allowed.