Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

streams.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 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 
10 #include <serialize.h>
11 
12 #include <algorithm>
13 #include <assert.h>
14 #include <ios>
15 #include <limits>
16 #include <map>
17 #include <set>
18 #include <stdint.h>
19 #include <stdio.h>
20 #include <string>
21 #include <string.h>
22 #include <utility>
23 #include <vector>
24 
25 /* Minimal stream for overwriting and/or appending to an existing byte vector
26  *
27  * The referenced vector will grow as necessary
28  */
30 {
31  public:
32 
33 /*
34  * @param[in] nTypeIn Serialization Type
35  * @param[in] nVersionIn Serialization Version (including any flags)
36  * @param[in] vchDataIn Referenced byte vector to overwrite/append
37  * @param[in] nPosIn Starting position. Vector index where writes should start. The vector will initially
38  * grow as necessary to max(nPosIn, vec.size()). So to append, use vec.size().
39 */
40  CVectorWriter(int nTypeIn, int nVersionIn, std::vector<unsigned char>& vchDataIn, size_t nPosIn) : nType(nTypeIn), nVersion(nVersionIn), vchData(vchDataIn), nPos(nPosIn)
41  {
42  if(nPos > vchData.size())
43  vchData.resize(nPos);
44  }
45 /*
46  * (other params same as above)
47  * @param[in] args A list of items to serialize starting at nPosIn.
48 */
49  template <typename... Args>
50  CVectorWriter(int nTypeIn, int nVersionIn, std::vector<unsigned char>& vchDataIn, size_t nPosIn, Args&&... args) : CVectorWriter(nTypeIn, nVersionIn, vchDataIn, nPosIn)
51  {
52  ::SerializeMany(*this, std::forward<Args>(args)...);
53  }
54  void write(const char* pch, size_t nSize)
55  {
56  assert(nPos <= vchData.size());
57  size_t nOverwrite = std::min(nSize, vchData.size() - nPos);
58  if (nOverwrite) {
59  memcpy(vchData.data() + nPos, reinterpret_cast<const unsigned char*>(pch), nOverwrite);
60  }
61  if (nOverwrite < nSize) {
62  vchData.insert(vchData.end(), reinterpret_cast<const unsigned char*>(pch) + nOverwrite, reinterpret_cast<const unsigned char*>(pch) + nSize);
63  }
64  nPos += nSize;
65  }
66  template<typename T>
67  CVectorWriter& operator<<(const T& obj)
68  {
69  // Serialize to this stream
70  ::Serialize(*this, obj);
71  return (*this);
72  }
73  int GetVersion() const
74  {
75  return nVersion;
76  }
77  int GetType() const
78  {
79  return nType;
80  }
81  void seek(size_t nSize)
82  {
83  nPos += nSize;
84  if(nPos > vchData.size())
85  vchData.resize(nPos);
86  }
87  size_t size() const
88  {
89  return vchData.size() - nPos;
90  }
91 private:
92  const int nType;
93  const int nVersion;
94  std::vector<unsigned char>& vchData;
95  size_t nPos;
96 };
97 
104 {
105 protected:
108  unsigned int nReadPos;
109 
110  int nType;
111  int nVersion;
112 public:
113 
114  typedef vector_type::allocator_type allocator_type;
115  typedef vector_type::size_type size_type;
116  typedef vector_type::difference_type difference_type;
117  typedef vector_type::reference reference;
118  typedef vector_type::const_reference const_reference;
119  typedef vector_type::value_type value_type;
120  typedef vector_type::iterator iterator;
121  typedef vector_type::const_iterator const_iterator;
122  typedef vector_type::reverse_iterator reverse_iterator;
123 
124  explicit CDataStream(int nTypeIn, int nVersionIn)
125  {
126  Init(nTypeIn, nVersionIn);
127  }
128 
129  CDataStream(const_iterator pbegin, const_iterator pend, int nTypeIn, int nVersionIn) : vch(pbegin, pend)
130  {
131  Init(nTypeIn, nVersionIn);
132  }
133 
134  CDataStream(const char* pbegin, const char* pend, int nTypeIn, int nVersionIn) : vch(pbegin, pend)
135  {
136  Init(nTypeIn, nVersionIn);
137  }
138 
139  CDataStream(const vector_type& vchIn, int nTypeIn, int nVersionIn) : vch(vchIn.begin(), vchIn.end())
140  {
141  Init(nTypeIn, nVersionIn);
142  }
143 
144  CDataStream(const std::vector<char>& vchIn, int nTypeIn, int nVersionIn) : vch(vchIn.begin(), vchIn.end())
145  {
146  Init(nTypeIn, nVersionIn);
147  }
148 
149  CDataStream(const std::vector<unsigned char>& vchIn, int nTypeIn, int nVersionIn) : vch(vchIn.begin(), vchIn.end())
150  {
151  Init(nTypeIn, nVersionIn);
152  }
153 
154  template <typename... Args>
155  CDataStream(int nTypeIn, int nVersionIn, Args&&... args)
156  {
157  Init(nTypeIn, nVersionIn);
158  ::SerializeMany(*this, std::forward<Args>(args)...);
159  }
160 
161  void Init(int nTypeIn, int nVersionIn)
162  {
163  nReadPos = 0;
164  nType = nTypeIn;
165  nVersion = nVersionIn;
166  }
167 
169  {
170  vch.insert(vch.end(), b.begin(), b.end());
171  return *this;
172  }
173 
174  friend CDataStream operator+(const CDataStream& a, const CDataStream& b)
175  {
176  CDataStream ret = a;
177  ret += b;
178  return (ret);
179  }
180 
181  std::string str() const
182  {
183  return (std::string(begin(), end()));
184  }
185 
186 
187  //
188  // Vector subset
189  //
190  const_iterator begin() const { return vch.begin() + nReadPos; }
191  iterator begin() { return vch.begin() + nReadPos; }
192  const_iterator end() const { return vch.end(); }
193  iterator end() { return vch.end(); }
194  size_type size() const { return vch.size() - nReadPos; }
195  bool empty() const { return vch.size() == nReadPos; }
196  void resize(size_type n, value_type c=0) { vch.resize(n + nReadPos, c); }
197  void reserve(size_type n) { vch.reserve(n + nReadPos); }
198  const_reference operator[](size_type pos) const { return vch[pos + nReadPos]; }
199  reference operator[](size_type pos) { return vch[pos + nReadPos]; }
200  void clear() { vch.clear(); nReadPos = 0; }
201  iterator insert(iterator it, const char x=char()) { return vch.insert(it, x); }
202  void insert(iterator it, size_type n, const char x) { vch.insert(it, n, x); }
203  value_type* data() { return vch.data() + nReadPos; }
204  const value_type* data() const { return vch.data() + nReadPos; }
205 
206  void insert(iterator it, std::vector<char>::const_iterator first, std::vector<char>::const_iterator last)
207  {
208  if (last == first) return;
209  assert(last - first > 0);
210  if (it == vch.begin() + nReadPos && (unsigned int)(last - first) <= nReadPos)
211  {
212  // special case for inserting at the front when there's room
213  nReadPos -= (last - first);
214  memcpy(&vch[nReadPos], &first[0], last - first);
215  }
216  else
217  vch.insert(it, first, last);
218  }
219 
220  void insert(iterator it, const char* first, const char* last)
221  {
222  if (last == first) return;
223  assert(last - first > 0);
224  if (it == vch.begin() + nReadPos && (unsigned int)(last - first) <= nReadPos)
225  {
226  // special case for inserting at the front when there's room
227  nReadPos -= (last - first);
228  memcpy(&vch[nReadPos], &first[0], last - first);
229  }
230  else
231  vch.insert(it, first, last);
232  }
233 
235  {
236  if (it == vch.begin() + nReadPos)
237  {
238  // special case for erasing from the front
239  if (++nReadPos >= vch.size())
240  {
241  // whenever we reach the end, we take the opportunity to clear the buffer
242  nReadPos = 0;
243  return vch.erase(vch.begin(), vch.end());
244  }
245  return vch.begin() + nReadPos;
246  }
247  else
248  return vch.erase(it);
249  }
250 
252  {
253  if (first == vch.begin() + nReadPos)
254  {
255  // special case for erasing from the front
256  if (last == vch.end())
257  {
258  nReadPos = 0;
259  return vch.erase(vch.begin(), vch.end());
260  }
261  else
262  {
263  nReadPos = (last - vch.begin());
264  return last;
265  }
266  }
267  else
268  return vch.erase(first, last);
269  }
270 
271  inline void Compact()
272  {
273  vch.erase(vch.begin(), vch.begin() + nReadPos);
274  nReadPos = 0;
275  }
276 
278  {
279  // Rewind by n characters if the buffer hasn't been compacted yet
280  if (n > nReadPos)
281  return false;
282  nReadPos -= n;
283  return true;
284  }
285 
286 
287  //
288  // Stream subset
289  //
290  bool eof() const { return size() == 0; }
291  CDataStream* rdbuf() { return this; }
292  int in_avail() const { return size(); }
293 
294  void SetType(int n) { nType = n; }
295  int GetType() const { return nType; }
296  void SetVersion(int n) { nVersion = n; }
297  int GetVersion() const { return nVersion; }
298 
299  void read(char* pch, size_t nSize)
300  {
301  if (nSize == 0) return;
302 
303  // Read from the beginning of the buffer
304  unsigned int nReadPosNext = nReadPos + nSize;
305  if (nReadPosNext > vch.size()) {
306  throw std::ios_base::failure("CDataStream::read(): end of data");
307  }
308  memcpy(pch, &vch[nReadPos], nSize);
309  if (nReadPosNext == vch.size())
310  {
311  nReadPos = 0;
312  vch.clear();
313  return;
314  }
315  nReadPos = nReadPosNext;
316  }
317 
318  void ignore(int nSize)
319  {
320  // Ignore from the beginning of the buffer
321  if (nSize < 0) {
322  throw std::ios_base::failure("CDataStream::ignore(): nSize negative");
323  }
324  unsigned int nReadPosNext = nReadPos + nSize;
325  if (nReadPosNext >= vch.size())
326  {
327  if (nReadPosNext > vch.size())
328  throw std::ios_base::failure("CDataStream::ignore(): end of data");
329  nReadPos = 0;
330  vch.clear();
331  return;
332  }
333  nReadPos = nReadPosNext;
334  }
335 
336  void write(const char* pch, size_t nSize)
337  {
338  // Write to the end of the buffer
339  vch.insert(vch.end(), pch, pch + nSize);
340  }
341 
342  template<typename Stream>
343  void Serialize(Stream& s) const
344  {
345  // Special case: stream << stream concatenates like stream += stream
346  if (!vch.empty())
347  s.write((char*)vch.data(), vch.size() * sizeof(value_type));
348  }
349 
350  template<typename T>
351  CDataStream& operator<<(const T& obj)
352  {
353  // Serialize to this stream
354  ::Serialize(*this, obj);
355  return (*this);
356  }
357 
358  template<typename T>
360  {
361  // Unserialize from this stream
362  ::Unserialize(*this, obj);
363  return (*this);
364  }
365 
367  d.insert(d.end(), begin(), end());
368  clear();
369  }
370 
376  void Xor(const std::vector<unsigned char>& key)
377  {
378  if (key.size() == 0) {
379  return;
380  }
381 
382  for (size_type i = 0, j = 0; i != size(); i++) {
383  vch[i] ^= key[j++];
384 
385  // This potentially acts on very many bytes of data, so it's
386  // important that we calculate `j`, i.e. the `key` index in this
387  // way instead of doing a %, which would effectively be a division
388  // for each byte Xor'd -- much slower than need be.
389  if (j == key.size())
390  j = 0;
391  }
392  }
393 };
394 
395 
396 
397 
398 
399 
400 
401 
402 
403 
411 {
412 private:
413  const int nType;
414  const int nVersion;
415 
416  FILE* file;
417 
418 public:
419  CAutoFile(FILE* filenew, int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn)
420  {
421  file = filenew;
422  }
423 
425  {
426  fclose();
427  }
428 
429  // Disallow copies
430  CAutoFile(const CAutoFile&) = delete;
431  CAutoFile& operator=(const CAutoFile&) = delete;
432 
433  void fclose()
434  {
435  if (file) {
436  ::fclose(file);
437  file = nullptr;
438  }
439  }
440 
445  FILE* release() { FILE* ret = file; file = nullptr; return ret; }
446 
451  FILE* Get() const { return file; }
452 
455  bool IsNull() const { return (file == nullptr); }
456 
457  //
458  // Stream subset
459  //
460  int GetType() const { return nType; }
461  int GetVersion() const { return nVersion; }
462 
463  void read(char* pch, size_t nSize)
464  {
465  if (!file)
466  throw std::ios_base::failure("CAutoFile::read: file handle is nullptr");
467  if (fread(pch, 1, nSize, file) != nSize)
468  throw std::ios_base::failure(feof(file) ? "CAutoFile::read: end of file" : "CAutoFile::read: fread failed");
469  }
470 
471  void ignore(size_t nSize)
472  {
473  if (!file)
474  throw std::ios_base::failure("CAutoFile::ignore: file handle is nullptr");
475  unsigned char data[4096];
476  while (nSize > 0) {
477  size_t nNow = std::min<size_t>(nSize, sizeof(data));
478  if (fread(data, 1, nNow, file) != nNow)
479  throw std::ios_base::failure(feof(file) ? "CAutoFile::ignore: end of file" : "CAutoFile::read: fread failed");
480  nSize -= nNow;
481  }
482  }
483 
484  void write(const char* pch, size_t nSize)
485  {
486  if (!file)
487  throw std::ios_base::failure("CAutoFile::write: file handle is nullptr");
488  if (fwrite(pch, 1, nSize, file) != nSize)
489  throw std::ios_base::failure("CAutoFile::write: write failed");
490  }
491 
492  template<typename T>
493  CAutoFile& operator<<(const T& obj)
494  {
495  // Serialize to this stream
496  if (!file)
497  throw std::ios_base::failure("CAutoFile::operator<<: file handle is nullptr");
498  ::Serialize(*this, obj);
499  return (*this);
500  }
501 
502  template<typename T>
504  {
505  // Unserialize from this stream
506  if (!file)
507  throw std::ios_base::failure("CAutoFile::operator>>: file handle is nullptr");
508  ::Unserialize(*this, obj);
509  return (*this);
510  }
511 };
512 
520 {
521 private:
522  const int nType;
523  const int nVersion;
524 
525  FILE *src; // source file
526  uint64_t nSrcPos; // how many bytes have been read from source
527  uint64_t nReadPos; // how many bytes have been read from this
528  uint64_t nReadLimit; // up to which position we're allowed to read
529  uint64_t nRewind; // how many bytes we guarantee to rewind
530  std::vector<char> vchBuf; // the buffer
531 
532 protected:
533  // read data from the source to fill the buffer
534  bool Fill() {
535  unsigned int pos = nSrcPos % vchBuf.size();
536  unsigned int readNow = vchBuf.size() - pos;
537  unsigned int nAvail = vchBuf.size() - (nSrcPos - nReadPos) - nRewind;
538  if (nAvail < readNow)
539  readNow = nAvail;
540  if (readNow == 0)
541  return false;
542  size_t nBytes = fread((void*)&vchBuf[pos], 1, readNow, src);
543  if (nBytes == 0) {
544  throw std::ios_base::failure(feof(src) ? "CBufferedFile::Fill: end of file" : "CBufferedFile::Fill: fread failed");
545  } else {
546  nSrcPos += nBytes;
547  return true;
548  }
549  }
550 
551 public:
552  CBufferedFile(FILE *fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn) :
553  nType(nTypeIn), nVersion(nVersionIn), nSrcPos(0), nReadPos(0), nReadLimit((uint64_t)(-1)), nRewind(nRewindIn), vchBuf(nBufSize, 0)
554  {
555  src = fileIn;
556  }
557 
559  {
560  fclose();
561  }
562 
563  // Disallow copies
564  CBufferedFile(const CBufferedFile&) = delete;
565  CBufferedFile& operator=(const CBufferedFile&) = delete;
566 
567  int GetVersion() const { return nVersion; }
568  int GetType() const { return nType; }
569 
570  void fclose()
571  {
572  if (src) {
573  ::fclose(src);
574  src = nullptr;
575  }
576  }
577 
578  // check whether we're at the end of the source file
579  bool eof() const {
580  return nReadPos == nSrcPos && feof(src);
581  }
582 
583  // read a number of bytes
584  void read(char *pch, size_t nSize) {
585  if (nSize + nReadPos > nReadLimit)
586  throw std::ios_base::failure("Read attempted past buffer limit");
587  if (nSize + nRewind > vchBuf.size())
588  throw std::ios_base::failure("Read larger than buffer size");
589  while (nSize > 0) {
590  if (nReadPos == nSrcPos)
591  Fill();
592  unsigned int pos = nReadPos % vchBuf.size();
593  size_t nNow = nSize;
594  if (nNow + pos > vchBuf.size())
595  nNow = vchBuf.size() - pos;
596  if (nNow + nReadPos > nSrcPos)
597  nNow = nSrcPos - nReadPos;
598  memcpy(pch, &vchBuf[pos], nNow);
599  nReadPos += nNow;
600  pch += nNow;
601  nSize -= nNow;
602  }
603  }
604 
605  // return the current reading position
606  uint64_t GetPos() const {
607  return nReadPos;
608  }
609 
610  // rewind to a given reading position
611  bool SetPos(uint64_t nPos) {
612  nReadPos = nPos;
613  if (nReadPos + nRewind < nSrcPos) {
615  return false;
616  } else if (nReadPos > nSrcPos) {
617  nReadPos = nSrcPos;
618  return false;
619  } else {
620  return true;
621  }
622  }
623 
624  bool Seek(uint64_t nPos) {
625  long nLongPos = nPos;
626  if (nPos != (uint64_t)nLongPos)
627  return false;
628  if (fseek(src, nLongPos, SEEK_SET))
629  return false;
630  nLongPos = ftell(src);
631  nSrcPos = nLongPos;
632  nReadPos = nLongPos;
633  return true;
634  }
635 
636  // prevent reading beyond a certain position
637  // no argument removes the limit
638  bool SetLimit(uint64_t nPos = (uint64_t)(-1)) {
639  if (nPos < nReadPos)
640  return false;
641  nReadLimit = nPos;
642  return true;
643  }
644 
645  template<typename T>
647  // Unserialize from this stream
648  ::Unserialize(*this, obj);
649  return (*this);
650  }
651 
652  // search for a given byte in the stream, and remain positioned on it
653  void FindByte(char ch) {
654  while (true) {
655  if (nReadPos == nSrcPos)
656  Fill();
657  if (vchBuf[nReadPos % vchBuf.size()] == ch)
658  break;
659  nReadPos++;
660  }
661  }
662 };
663 
664 #endif // BITCOIN_STREAMS_H
const int nType
Definition: streams.h:522
CVectorWriter & operator<<(const T &obj)
Definition: streams.h:67
void Init(int nTypeIn, int nVersionIn)
Definition: streams.h:161
CSerializeData vector_type
Definition: streams.h:106
void ignore(size_t nSize)
Definition: streams.h:471
uint64_t nReadPos
Definition: streams.h:527
vector_type::iterator iterator
Definition: streams.h:120
vector_type::allocator_type allocator_type
Definition: streams.h:114
vector_type vch
Definition: streams.h:107
std::vector< unsigned char > & vchData
Definition: streams.h:94
void Compact()
Definition: streams.h:271
int GetVersion() const
Definition: streams.h:297
CAutoFile & operator>>(T &obj)
Definition: streams.h:503
CDataStream(const_iterator pbegin, const_iterator pend, int nTypeIn, int nVersionIn)
Definition: streams.h:129
unsigned int nReadPos
Definition: streams.h:108
size_t nPos
Definition: streams.h:95
int GetType() const
Definition: streams.h:295
int GetType() const
Definition: streams.h:77
CDataStream(const std::vector< unsigned char > &vchIn, int nTypeIn, int nVersionIn)
Definition: streams.h:149
void write(const char *pch, size_t nSize)
Definition: streams.h:54
const int nVersion
Definition: streams.h:414
vector_type::size_type size_type
Definition: streams.h:115
std::string str() const
Definition: streams.h:181
void resize(size_type n, value_type c=0)
Definition: streams.h:196
CDataStream(const vector_type &vchIn, int nTypeIn, int nVersionIn)
Definition: streams.h:139
void Serialize(Stream &s) const
Definition: streams.h:343
vector_type::reference reference
Definition: streams.h:117
int GetType() const
Definition: streams.h:568
vector_type::value_type value_type
Definition: streams.h:119
void Xor(const std::vector< unsigned char > &key)
XOR the contents of this stream with a certain key.
Definition: streams.h:376
value_type * data()
Definition: streams.h:203
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:103
void write(const char *pch, size_t nSize)
Definition: streams.h:336
bool empty() const
Definition: streams.h:195
vector_type::reverse_iterator reverse_iterator
Definition: streams.h:122
int GetVersion() const
Definition: streams.h:461
iterator erase(iterator it)
Definition: streams.h:234
CAutoFile(FILE *filenew, int nTypeIn, int nVersionIn)
Definition: streams.h:419
iterator end()
Definition: streams.h:193
const int nVersion
Definition: streams.h:523
friend CDataStream operator+(const CDataStream &a, const CDataStream &b)
Definition: streams.h:174
CDataStream * rdbuf()
Definition: streams.h:291
~CAutoFile()
Definition: streams.h:424
CDataStream(int nTypeIn, int nVersionIn)
Definition: streams.h:124
void insert(iterator it, std::vector< char >::const_iterator first, std::vector< char >::const_iterator last)
Definition: streams.h:206
bool IsNull() const
Return true if the wrapped FILE* is nullptr, false otherwise.
Definition: streams.h:455
iterator insert(iterator it, const char x=char())
Definition: streams.h:201
FILE * release()
Get wrapped FILE* with transfer of ownership.
Definition: streams.h:445
void write(const char *pch, size_t nSize)
Definition: streams.h:484
void Serialize(Stream &s, char a)
Definition: serialize.h:184
CVectorWriter(int nTypeIn, int nVersionIn, std::vector< unsigned char > &vchDataIn, size_t nPosIn, Args &&... args)
Definition: streams.h:50
void read(char *pch, size_t nSize)
Definition: streams.h:299
vector_type::const_reference const_reference
Definition: streams.h:118
bool SetLimit(uint64_t nPos=(uint64_t)(-1))
Definition: streams.h:638
CDataStream(int nTypeIn, int nVersionIn, Args &&... args)
Definition: streams.h:155
void fclose()
Definition: streams.h:433
uint64_t GetPos() const
Definition: streams.h:606
const int nType
Definition: streams.h:92
CDataStream(const std::vector< char > &vchIn, int nTypeIn, int nVersionIn)
Definition: streams.h:144
uint64_t nReadLimit
Definition: streams.h:528
size_type size() const
Definition: streams.h:194
vector_type::const_iterator const_iterator
Definition: streams.h:121
void seek(size_t nSize)
Definition: streams.h:81
CBufferedFile(FILE *fileIn, uint64_t nBufSize, uint64_t nRewindIn, int nTypeIn, int nVersionIn)
Definition: streams.h:552
void ignore(int nSize)
Definition: streams.h:318
const value_type * data() const
Definition: streams.h:204
CDataStream(const char *pbegin, const char *pend, int nTypeIn, int nVersionIn)
Definition: streams.h:134
CDataStream & operator+=(const CDataStream &b)
Definition: streams.h:168
CDataStream & operator>>(T &obj)
Definition: streams.h:359
void GetAndClear(CSerializeData &d)
Definition: streams.h:366
iterator begin()
Definition: streams.h:191
int GetVersion() const
Definition: streams.h:73
void read(char *pch, size_t nSize)
Definition: streams.h:463
void read(char *pch, size_t nSize)
Definition: streams.h:584
reference operator[](size_type pos)
Definition: streams.h:199
bool SetPos(uint64_t nPos)
Definition: streams.h:611
bool Rewind(size_type n)
Definition: streams.h:277
void SerializeMany(Stream &s)
Definition: serialize.h:1236
const_reference operator[](size_type pos) const
Definition: streams.h:198
int GetType() const
Definition: streams.h:460
FILE * Get() const
Get wrapped FILE* without transfer of ownership.
Definition: streams.h:451
void fclose()
Definition: streams.h:570
const int nVersion
Definition: streams.h:93
const_iterator end() const
Definition: streams.h:192
const_iterator begin() const
Definition: streams.h:190
CDataStream & operator<<(const T &obj)
Definition: streams.h:351
void FindByte(char ch)
Definition: streams.h:653
void reserve(size_type n)
Definition: streams.h:197
void * memcpy(void *a, const void *b, size_t c)
int nVersion
Definition: streams.h:111
FILE * src
Definition: streams.h:525
void Unserialize(Stream &s, char &a)
Definition: serialize.h:196
vector_type::difference_type difference_type
Definition: streams.h:116
CAutoFile & operator=(const CAutoFile &)=delete
void insert(iterator it, const char *first, const char *last)
Definition: streams.h:220
void clear()
Definition: streams.h:200
uint64_t nSrcPos
Definition: streams.h:526
bool Fill()
Definition: streams.h:534
std::vector< char, zero_after_free_allocator< char > > CSerializeData
Definition: zeroafterfree.h:46
FILE * file
Definition: streams.h:416
std::vector< char > vchBuf
Definition: streams.h:530
iterator erase(iterator first, iterator last)
Definition: streams.h:251
uint64_t nRewind
Definition: streams.h:529
int GetVersion() const
Definition: streams.h:567
const int nType
Definition: streams.h:413
Non-refcounted RAII wrapper around a FILE* that implements a ring buffer to deserialize from...
Definition: streams.h:519
void SetVersion(int n)
Definition: streams.h:296
CBufferedFile & operator>>(T &obj)
Definition: streams.h:646
CBufferedFile & operator=(const CBufferedFile &)=delete
int nType
Definition: streams.h:110
bool Seek(uint64_t nPos)
Definition: streams.h:624
bool eof() const
Definition: streams.h:290
CAutoFile & operator<<(const T &obj)
Definition: streams.h:493
void insert(iterator it, size_type n, const char x)
Definition: streams.h:202
~CBufferedFile()
Definition: streams.h:558
int in_avail() const
Definition: streams.h:292
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:410
size_t size() const
Definition: streams.h:87
CVectorWriter(int nTypeIn, int nVersionIn, std::vector< unsigned char > &vchDataIn, size_t nPosIn)
Definition: streams.h:40
void SetType(int n)
Definition: streams.h:294
bool eof() const
Definition: streams.h:579
Released under the MIT license