30 : std::istream(this), _stream(stream), data_buf_(buffer), data_size_(buffer), _base64_state(0), _base64_padding(0), _byte_read(0), _byte_limit(limit)
39 void Base64Reader::set_b64(
char val)
41 switch (_base64_state)
70 return std::char_traits<char>::eof();
73 if ((_byte_limit > 0) && (_byte_read >= _byte_limit))
75 return std::char_traits<char>::eof();
79 std::vector<char> buffer(data_size_);
84 size_t bytes_to_read = _byte_limit - _byte_read;
90 bytes_to_read -= _base64_state;
94 "[Base64Reader] base64 bytes to read: " << bytes_to_read <<
95 "; payload bytes: " << (_byte_limit - _byte_read) <<
99 if (bytes_to_read > data_size_) bytes_to_read = data_size_;
102 _stream.read((
char*)&buffer[0], bytes_to_read);
106 _stream.read((
char*)&buffer[0], data_size_);
109 size_t len = _stream.gcount();
112 size_t decoded_bytes = 0;
114 for (
size_t i = 0; i < len; ++i)
126 switch (_base64_state)
130 return std::char_traits<char>::eof();
134 return std::char_traits<char>::eof();
143 if (_base64_padding == 0)
157 set_b64(static_cast<char>(c));
163 if (_base64_state == 4)
165 switch (_base64_padding)
168 data_buf_[decoded_bytes] = _group.
get_0(); decoded_bytes++;
169 data_buf_[decoded_bytes] = _group.
get_1(); decoded_bytes++;
170 data_buf_[decoded_bytes] = _group.
get_2(); decoded_bytes++;
174 data_buf_[decoded_bytes] = _group.
get_0(); decoded_bytes++;
175 data_buf_[decoded_bytes] = _group.
get_1(); decoded_bytes++;
179 data_buf_[decoded_bytes] = _group.
get_0(); decoded_bytes++;
190 if (decoded_bytes == 0)
198 setg(&data_buf_[0], &data_buf_[0], &data_buf_[0] + decoded_bytes);
202 _byte_read += decoded_bytes;
205 return std::char_traits<char>::not_eof(data_buf_[0]);