Bitcoin Core  28.1.0
P2P Digital Currency
streams.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2022 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_STREAMS_H
7 #define BITCOIN_STREAMS_H
8 
9 #include <serialize.h>
10 #include <span.h>
12 #include <util/overflow.h>
13 
14 #include <algorithm>
15 #include <assert.h>
16 #include <cstddef>
17 #include <cstdio>
18 #include <ios>
19 #include <limits>
20 #include <optional>
21 #include <stdint.h>
22 #include <string.h>
23 #include <string>
24 #include <utility>
25 #include <vector>
26 
27 namespace util {
28 inline void Xor(Span<std::byte> write, Span<const std::byte> key, size_t key_offset = 0)
29 {
30  if (key.size() == 0) {
31  return;
32  }
33  key_offset %= key.size();
34 
35  for (size_t i = 0, j = key_offset; i != write.size(); i++) {
36  write[i] ^= key[j++];
37 
38  // This potentially acts on very many bytes of data, so it's
39  // important that we calculate `j`, i.e. the `key` index in this
40  // way instead of doing a %, which would effectively be a division
41  // for each byte Xor'd -- much slower than need be.
42  if (j == key.size())
43  j = 0;
44  }
45 }
46 } // namespace util
47 
48 /* Minimal stream for overwriting and/or appending to an existing byte vector
49  *
50  * The referenced vector will grow as necessary
51  */
53 {
54 public:
55 /*
56  * @param[in] vchDataIn Referenced byte vector to overwrite/append
57  * @param[in] nPosIn Starting position. Vector index where writes should start. The vector will initially
58  * grow as necessary to max(nPosIn, vec.size()). So to append, use vec.size().
59 */
60  VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn) : vchData{vchDataIn}, nPos{nPosIn}
61  {
62  if(nPos > vchData.size())
63  vchData.resize(nPos);
64  }
65 /*
66  * (other params same as above)
67  * @param[in] args A list of items to serialize starting at nPosIn.
68 */
69  template <typename... Args>
70  VectorWriter(std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : VectorWriter{vchDataIn, nPosIn}
71  {
72  ::SerializeMany(*this, std::forward<Args>(args)...);
73  }
75  {
76  assert(nPos <= vchData.size());
77  size_t nOverwrite = std::min(src.size(), vchData.size() - nPos);
78  if (nOverwrite) {
79  memcpy(vchData.data() + nPos, src.data(), nOverwrite);
80  }
81  if (nOverwrite < src.size()) {
82  vchData.insert(vchData.end(), UCharCast(src.data()) + nOverwrite, UCharCast(src.end()));
83  }
84  nPos += src.size();
85  }
86  template <typename T>
87  VectorWriter& operator<<(const T& obj)
88  {
89  ::Serialize(*this, obj);
90  return (*this);
91  }
92 
93 private:
94  std::vector<unsigned char>& vchData;
95  size_t nPos;
96 };
97 
101 {
102 private:
104 
105 public:
109  explicit SpanReader(Span<const unsigned char> data) : m_data{data} {}
110 
111  template<typename T>
113  {
114  ::Unserialize(*this, obj);
115  return (*this);
116  }
117 
118  size_t size() const { return m_data.size(); }
119  bool empty() const { return m_data.empty(); }
120 
122  {
123  if (dst.size() == 0) {
124  return;
125  }
126 
127  // Read from the beginning of the buffer
128  if (dst.size() > m_data.size()) {
129  throw std::ios_base::failure("SpanReader::read(): end of data");
130  }
131  memcpy(dst.data(), m_data.data(), dst.size());
132  m_data = m_data.subspan(dst.size());
133  }
134 
135  void ignore(size_t n)
136  {
137  m_data = m_data.subspan(n);
138  }
139 };
140 
147 {
148 protected:
151  vector_type::size_type m_read_pos{0};
152 
153 public:
154  typedef vector_type::allocator_type allocator_type;
155  typedef vector_type::size_type size_type;
156  typedef vector_type::difference_type difference_type;
157  typedef vector_type::reference reference;
158  typedef vector_type::const_reference const_reference;
159  typedef vector_type::value_type value_type;
160  typedef vector_type::iterator iterator;
161  typedef vector_type::const_iterator const_iterator;
162  typedef vector_type::reverse_iterator reverse_iterator;
163 
164  explicit DataStream() = default;
166  explicit DataStream(Span<const value_type> sp) : vch(sp.data(), sp.data() + sp.size()) {}
167 
168  std::string str() const
169  {
170  return std::string{UCharCast(data()), UCharCast(data() + size())};
171  }
172 
173 
174  //
175  // Vector subset
176  //
177  const_iterator begin() const { return vch.begin() + m_read_pos; }
178  iterator begin() { return vch.begin() + m_read_pos; }
179  const_iterator end() const { return vch.end(); }
180  iterator end() { return vch.end(); }
181  size_type size() const { return vch.size() - m_read_pos; }
182  bool empty() const { return vch.size() == m_read_pos; }
183  void resize(size_type n, value_type c = value_type{}) { vch.resize(n + m_read_pos, c); }
184  void reserve(size_type n) { vch.reserve(n + m_read_pos); }
185  const_reference operator[](size_type pos) const { return vch[pos + m_read_pos]; }
186  reference operator[](size_type pos) { return vch[pos + m_read_pos]; }
187  void clear() { vch.clear(); m_read_pos = 0; }
188  value_type* data() { return vch.data() + m_read_pos; }
189  const value_type* data() const { return vch.data() + m_read_pos; }
190 
191  inline void Compact()
192  {
193  vch.erase(vch.begin(), vch.begin() + m_read_pos);
194  m_read_pos = 0;
195  }
196 
197  bool Rewind(std::optional<size_type> n = std::nullopt)
198  {
199  // Total rewind if no size is passed
200  if (!n) {
201  m_read_pos = 0;
202  return true;
203  }
204  // Rewind by n characters if the buffer hasn't been compacted yet
205  if (*n > m_read_pos)
206  return false;
207  m_read_pos -= *n;
208  return true;
209  }
210 
211 
212  //
213  // Stream subset
214  //
215  bool eof() const { return size() == 0; }
216  int in_avail() const { return size(); }
217 
219  {
220  if (dst.size() == 0) return;
221 
222  // Read from the beginning of the buffer
223  auto next_read_pos{CheckedAdd(m_read_pos, dst.size())};
224  if (!next_read_pos.has_value() || next_read_pos.value() > vch.size()) {
225  throw std::ios_base::failure("DataStream::read(): end of data");
226  }
227  memcpy(dst.data(), &vch[m_read_pos], dst.size());
228  if (next_read_pos.value() == vch.size()) {
229  m_read_pos = 0;
230  vch.clear();
231  return;
232  }
233  m_read_pos = next_read_pos.value();
234  }
235 
236  void ignore(size_t num_ignore)
237  {
238  // Ignore from the beginning of the buffer
239  auto next_read_pos{CheckedAdd(m_read_pos, num_ignore)};
240  if (!next_read_pos.has_value() || next_read_pos.value() > vch.size()) {
241  throw std::ios_base::failure("DataStream::ignore(): end of data");
242  }
243  if (next_read_pos.value() == vch.size()) {
244  m_read_pos = 0;
245  vch.clear();
246  return;
247  }
248  m_read_pos = next_read_pos.value();
249  }
250 
252  {
253  // Write to the end of the buffer
254  vch.insert(vch.end(), src.begin(), src.end());
255  }
256 
257  template<typename T>
258  DataStream& operator<<(const T& obj)
259  {
260  ::Serialize(*this, obj);
261  return (*this);
262  }
263 
264  template<typename T>
266  {
267  ::Unserialize(*this, obj);
268  return (*this);
269  }
270 
276  void Xor(const std::vector<unsigned char>& key)
277  {
279  }
280 };
281 
282 template <typename IStream>
284 {
285 private:
286  IStream& m_istream;
287 
290  uint8_t m_buffer{0};
291 
295  int m_offset{8};
296 
297 public:
298  explicit BitStreamReader(IStream& istream) : m_istream(istream) {}
299 
303  uint64_t Read(int nbits) {
304  if (nbits < 0 || nbits > 64) {
305  throw std::out_of_range("nbits must be between 0 and 64");
306  }
307 
308  uint64_t data = 0;
309  while (nbits > 0) {
310  if (m_offset == 8) {
311  m_istream >> m_buffer;
312  m_offset = 0;
313  }
314 
315  int bits = std::min(8 - m_offset, nbits);
316  data <<= bits;
317  data |= static_cast<uint8_t>(m_buffer << m_offset) >> (8 - bits);
318  m_offset += bits;
319  nbits -= bits;
320  }
321  return data;
322  }
323 };
324 
325 template <typename OStream>
327 {
328 private:
329  OStream& m_ostream;
330 
333  uint8_t m_buffer{0};
334 
338  int m_offset{0};
339 
340 public:
341  explicit BitStreamWriter(OStream& ostream) : m_ostream(ostream) {}
342 
344  {
345  Flush();
346  }
347 
351  void Write(uint64_t data, int nbits) {
352  if (nbits < 0 || nbits > 64) {
353  throw std::out_of_range("nbits must be between 0 and 64");
354  }
355 
356  while (nbits > 0) {
357  int bits = std::min(8 - m_offset, nbits);
358  m_buffer |= (data << (64 - nbits)) >> (64 - 8 + m_offset);
359  m_offset += bits;
360  nbits -= bits;
361 
362  if (m_offset == 8) {
363  Flush();
364  }
365  }
366  }
367 
371  void Flush() {
372  if (m_offset == 0) {
373  return;
374  }
375 
376  m_ostream << m_buffer;
377  m_buffer = 0;
378  m_offset = 0;
379  }
380 };
381 
388 class AutoFile
389 {
390 protected:
391  std::FILE* m_file;
392  std::vector<std::byte> m_xor;
393  std::optional<int64_t> m_position;
394 
395 public:
396  explicit AutoFile(std::FILE* file, std::vector<std::byte> data_xor={});
397 
398  ~AutoFile() { fclose(); }
399 
400  // Disallow copies
401  AutoFile(const AutoFile&) = delete;
402  AutoFile& operator=(const AutoFile&) = delete;
403 
404  bool feof() const { return std::feof(m_file); }
405 
406  int fclose()
407  {
408  if (auto rel{release()}) return std::fclose(rel);
409  return 0;
410  }
411 
416  std::FILE* release()
417  {
418  std::FILE* ret{m_file};
419  m_file = nullptr;
420  return ret;
421  }
422 
425  bool IsNull() const { return m_file == nullptr; }
426 
428  void SetXor(std::vector<std::byte> data_xor) { m_xor = data_xor; }
429 
431  std::size_t detail_fread(Span<std::byte> dst);
432 
433  void seek(int64_t offset, int origin);
434  int64_t tell();
435 
436  //
437  // Stream subset
438  //
439  void read(Span<std::byte> dst);
440  void ignore(size_t nSize);
441  void write(Span<const std::byte> src);
442 
443  template <typename T>
444  AutoFile& operator<<(const T& obj)
445  {
446  ::Serialize(*this, obj);
447  return *this;
448  }
449 
450  template <typename T>
452  {
453  ::Unserialize(*this, obj);
454  return *this;
455  }
456 
457  bool Commit();
458  bool IsError();
459  bool Truncate(unsigned size);
460 };
461 
469 {
470 private:
472  uint64_t nSrcPos{0};
473  uint64_t m_read_pos{0};
474  uint64_t nReadLimit;
475  uint64_t nRewind;
476  std::vector<std::byte> vchBuf;
477 
479  bool Fill() {
480  unsigned int pos = nSrcPos % vchBuf.size();
481  unsigned int readNow = vchBuf.size() - pos;
482  unsigned int nAvail = vchBuf.size() - (nSrcPos - m_read_pos) - nRewind;
483  if (nAvail < readNow)
484  readNow = nAvail;
485  if (readNow == 0)
486  return false;
487  size_t nBytes{m_src.detail_fread(Span{vchBuf}.subspan(pos, readNow))};
488  if (nBytes == 0) {
489  throw std::ios_base::failure{m_src.feof() ? "BufferedFile::Fill: end of file" : "BufferedFile::Fill: fread failed"};
490  }
491  nSrcPos += nBytes;
492  return true;
493  }
494 
500  std::pair<std::byte*, size_t> AdvanceStream(size_t length)
501  {
503  if (m_read_pos + length > nReadLimit) {
504  throw std::ios_base::failure("Attempt to position past buffer limit");
505  }
506  // If there are no bytes available, read from the file.
507  if (m_read_pos == nSrcPos && length > 0) Fill();
508 
509  size_t buffer_offset{static_cast<size_t>(m_read_pos % vchBuf.size())};
510  size_t buffer_available{static_cast<size_t>(vchBuf.size() - buffer_offset)};
511  size_t bytes_until_source_pos{static_cast<size_t>(nSrcPos - m_read_pos)};
512  size_t advance{std::min({length, buffer_available, bytes_until_source_pos})};
513  m_read_pos += advance;
514  return std::make_pair(&vchBuf[buffer_offset], advance);
515  }
516 
517 public:
518  BufferedFile(AutoFile& file, uint64_t nBufSize, uint64_t nRewindIn)
519  : m_src{file}, nReadLimit{std::numeric_limits<uint64_t>::max()}, nRewind{nRewindIn}, vchBuf(nBufSize, std::byte{0})
520  {
521  if (nRewindIn >= nBufSize)
522  throw std::ios_base::failure("Rewind limit must be less than buffer size");
523  }
524 
526  bool eof() const {
527  return m_read_pos == nSrcPos && m_src.feof();
528  }
529 
532  {
533  while (dst.size() > 0) {
534  auto [buffer_pointer, length]{AdvanceStream(dst.size())};
535  memcpy(dst.data(), buffer_pointer, length);
536  dst = dst.subspan(length);
537  }
538  }
539 
542  void SkipTo(const uint64_t file_pos)
543  {
544  assert(file_pos >= m_read_pos);
545  while (m_read_pos < file_pos) AdvanceStream(file_pos - m_read_pos);
546  }
547 
549  uint64_t GetPos() const {
550  return m_read_pos;
551  }
552 
554  bool SetPos(uint64_t nPos) {
555  size_t bufsize = vchBuf.size();
556  if (nPos + bufsize < nSrcPos) {
557  // rewinding too far, rewind as far as possible
558  m_read_pos = nSrcPos - bufsize;
559  return false;
560  }
561  if (nPos > nSrcPos) {
562  // can't go this far forward, go as far as possible
564  return false;
565  }
566  m_read_pos = nPos;
567  return true;
568  }
569 
572  bool SetLimit(uint64_t nPos = std::numeric_limits<uint64_t>::max()) {
573  if (nPos < m_read_pos)
574  return false;
575  nReadLimit = nPos;
576  return true;
577  }
578 
579  template<typename T>
581  ::Unserialize(*this, obj);
582  return (*this);
583  }
584 
586  void FindByte(std::byte byte)
587  {
588  // For best performance, avoid mod operation within the loop.
589  size_t buf_offset{size_t(m_read_pos % uint64_t(vchBuf.size()))};
590  while (true) {
591  if (m_read_pos == nSrcPos) {
592  // No more bytes available; read from the file into the buffer,
593  // setting nSrcPos to one beyond the end of the new data.
594  // Throws exception if end-of-file reached.
595  Fill();
596  }
597  const size_t len{std::min<size_t>(vchBuf.size() - buf_offset, nSrcPos - m_read_pos)};
598  const auto it_start{vchBuf.begin() + buf_offset};
599  const auto it_find{std::find(it_start, it_start + len, byte)};
600  const size_t inc{size_t(std::distance(it_start, it_find))};
601  m_read_pos += inc;
602  if (inc < len) break;
603  buf_offset += inc;
604  if (buf_offset >= vchBuf.size()) buf_offset = 0;
605  }
606  }
607 };
608 
609 #endif // BITCOIN_STREAMS_H
AutoFile & m_src
Definition: streams.h:471
bool eof() const
Definition: streams.h:215
CONSTEXPR_IF_NOT_DEBUG Span< C > subspan(std::size_t offset) const noexcept
Definition: span.h:195
void SetXor(std::vector< std::byte > data_xor)
Continue with a different XOR key.
Definition: streams.h:428
Span< const unsigned char > m_data
Definition: streams.h:103
DataStream()=default
int ret
std::vector< std::byte > vchBuf
the buffer
Definition: streams.h:476
uint64_t GetPos() const
return the current reading position
Definition: streams.h:549
void reserve(size_type n)
Definition: streams.h:184
vector_type::const_reference const_reference
Definition: streams.h:158
vector_type::iterator iterator
Definition: streams.h:160
assert(!tx.IsCoinBase())
void Compact()
Definition: streams.h:191
size_t nPos
Definition: streams.h:95
constexpr C * end() const noexcept
Definition: span.h:176
VectorWriter(std::vector< unsigned char > &vchDataIn, size_t nPosIn)
Definition: streams.h:60
AutoFile & operator>>(T &&obj)
Definition: streams.h:451
Span< std::byte > MakeWritableByteSpan(V &&v) noexcept
Definition: span.h:282
int in_avail() const
Definition: streams.h:216
void SkipTo(const uint64_t file_pos)
Move the read position ahead in the stream to the given position.
Definition: streams.h:542
constexpr std::size_t size() const noexcept
Definition: span.h:187
~AutoFile()
Definition: streams.h:398
size_t size() const
Definition: streams.h:118
vector_type::difference_type difference_type
Definition: streams.h:156
uint64_t nRewind
how many bytes we guarantee to rewind
Definition: streams.h:475
Wrapper around an AutoFile& that implements a ring buffer to deserialize from.
Definition: streams.h:468
void ignore(size_t num_ignore)
Definition: streams.h:236
void write(Span< const value_type > src)
Definition: streams.h:251
bool feof() const
Definition: streams.h:404
iterator end()
Definition: streams.h:180
void Write(uint64_t data, int nbits)
Write the nbits least significant bits of a 64-bit int to the output stream.
Definition: streams.h:351
vector_type::value_type value_type
Definition: streams.h:159
std::FILE * release()
Get wrapped FILE* with transfer of ownership.
Definition: streams.h:416
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:388
bool empty() const
Definition: streams.h:182
value_type * data()
Definition: streams.h:188
bool empty() const
Definition: streams.h:119
uint8_t m_buffer
Buffered byte read in from the input stream.
Definition: streams.h:290
bool SetLimit(uint64_t nPos=std::numeric_limits< uint64_t >::max())
prevent reading beyond a certain position no argument removes the limit
Definition: streams.h:572
Minimal stream for reading from an existing byte array by Span.
Definition: streams.h:100
std::optional< T > CheckedAdd(const T i, const T j) noexcept
Definition: overflow.h:24
DataStream(Span< const uint8_t > sp)
Definition: streams.h:165
vector_type::size_type m_read_pos
Definition: streams.h:151
std::optional< int64_t > m_position
Definition: streams.h:393
vector_type::size_type size_type
Definition: streams.h:155
void Xor(Span< std::byte > write, Span< const std::byte > key, size_t key_offset=0)
Definition: streams.h:28
BitStreamReader(IStream &istream)
Definition: streams.h:298
int64_t tell()
Definition: streams.cpp:53
vector_type::reverse_iterator reverse_iterator
Definition: streams.h:162
const_iterator end() const
Definition: streams.h:179
bool Rewind(std::optional< size_type > n=std::nullopt)
Definition: streams.h:197
std::FILE * m_file
Definition: streams.h:391
DataStream(Span< const value_type > sp)
Definition: streams.h:166
void Unserialize(Stream &, V)=delete
ArgsManager & args
Definition: bitcoind.cpp:270
bool Commit()
Definition: streams.cpp:104
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:146
std::vector< std::byte, zero_after_free_allocator< std::byte > > SerializeData
Byte-vector that clears its contents before deletion.
Definition: zeroafterfree.h:49
DataStream & operator<<(const T &obj)
Definition: streams.h:258
AutoFile & operator<<(const T &obj)
Definition: streams.h:444
BufferedFile & operator>>(T &&obj)
Definition: streams.h:580
vector_type::allocator_type allocator_type
Definition: streams.h:154
vector_type::const_iterator const_iterator
Definition: streams.h:161
uint64_t nSrcPos
how many bytes have been read from source
Definition: streams.h:472
std::vector< std::byte > m_xor
Definition: streams.h:392
IStream & m_istream
Definition: streams.h:286
bool Fill()
read data from the source to fill the buffer
Definition: streams.h:479
AutoFile & operator=(const AutoFile &)=delete
std::pair< std::byte *, size_t > AdvanceStream(size_t length)
Advance the stream&#39;s read pointer (m_read_pos) by up to &#39;length&#39; bytes, filling the buffer from the f...
Definition: streams.h:500
void read(Span< std::byte > dst)
Definition: streams.cpp:59
SerializeData vector_type
Definition: streams.h:149
uint64_t Read(int nbits)
Read the specified number of bits from the stream.
Definition: streams.h:303
const_reference operator[](size_type pos) const
Definition: streams.h:185
DataStream & operator>>(T &&obj)
Definition: streams.h:265
void Flush()
Flush any unwritten bits to the output stream, padding with 0&#39;s to the next byte boundary.
Definition: streams.h:371
void FindByte(std::byte byte)
search for a given byte in the stream, and remain positioned on it
Definition: streams.h:586
const_iterator begin() const
Definition: streams.h:177
size_type size() const
Definition: streams.h:181
constexpr C * begin() const noexcept
Definition: span.h:175
std::string str() const
Definition: streams.h:168
uint8_t m_buffer
Buffered byte waiting to be written to the output stream.
Definition: streams.h:333
void resize(size_type n, value_type c=value_type{})
Definition: streams.h:183
std::vector< unsigned char > & vchData
Definition: streams.h:94
void clear()
Definition: streams.h:187
void write(Span< const std::byte > src)
Definition: streams.h:74
int m_offset
Number of high order bits in m_buffer already written by previous Write() calls and not yet flushed t...
Definition: streams.h:338
bool Truncate(unsigned size)
Definition: streams.cpp:114
bool SetPos(uint64_t nPos)
rewind to a given reading position
Definition: streams.h:554
const value_type * data() const
Definition: streams.h:189
constexpr C * data() const noexcept
Definition: span.h:174
AutoFile(std::FILE *file, std::vector< std::byte > data_xor={})
Definition: streams.cpp:11
int m_offset
Number of high order bits in m_buffer already returned by previous Read() calls.
Definition: streams.h:295
void Serialize(Stream &, V)=delete
reference operator[](size_type pos)
Definition: streams.h:186
void Xor(const std::vector< unsigned char > &key)
XOR the contents of this stream with a certain key.
Definition: streams.h:276
Span< const std::byte > MakeByteSpan(V &&v) noexcept
Definition: span.h:277
VectorWriter & operator<<(const T &obj)
Definition: streams.h:87
uint64_t nReadLimit
up to which position we&#39;re allowed to read
Definition: streams.h:474
void ignore(size_t n)
Definition: streams.h:135
int fclose()
Definition: streams.h:406
constexpr bool empty() const noexcept
Definition: span.h:189
Span< const std::byte > AsBytes(Span< T > s) noexcept
Definition: span.h:266
VectorWriter(std::vector< unsigned char > &vchDataIn, size_t nPosIn, Args &&... args)
Definition: streams.h:70
bool eof() const
check whether we&#39;re at the end of the source file
Definition: streams.h:526
SpanReader(Span< const unsigned char > data)
Definition: streams.h:109
void seek(int64_t offset, int origin)
Definition: streams.cpp:32
unsigned char * UCharCast(char *c)
Definition: span.h:288
void SerializeMany(Stream &s, const Args &... args)
Support for (un)serializing many things at once.
Definition: serialize.h:992
BufferedFile(AutoFile &file, uint64_t nBufSize, uint64_t nRewindIn)
Definition: streams.h:518
A Span is an object that can refer to a contiguous sequence of objects.
Definition: solver.h:20
OStream & m_ostream
Definition: streams.h:329
vector_type vch
Definition: streams.h:150
void read(Span< std::byte > dst)
read a number of bytes
Definition: streams.h:531
iterator begin()
Definition: streams.h:178
vector_type::reference reference
Definition: streams.h:157
std::size_t detail_fread(Span< std::byte > dst)
Implementation detail, only used internally.
Definition: streams.cpp:20
void read(Span< std::byte > dst)
Definition: streams.h:121
void read(Span< value_type > dst)
Definition: streams.h:218
SpanReader & operator>>(T &&obj)
Definition: streams.h:112
bool IsError()
Definition: streams.cpp:109
void write(Span< const std::byte > src)
Definition: streams.cpp:80
void ignore(size_t nSize)
Definition: streams.cpp:66
BitStreamWriter(OStream &ostream)
Definition: streams.h:341
bool IsNull() const
Return true if the wrapped FILE* is nullptr, false otherwise.
Definition: streams.h:425
uint64_t m_read_pos
how many bytes have been read from this
Definition: streams.h:473