Changeset View
Changeset View
Standalone View
Standalone View
src/streams.h
Show All 32 Lines | OverrideStream(Stream *stream_, int nType_, int nVersion_) | ||||
: stream(stream_), nType(nType_), nVersion(nVersion_) {} | : stream(stream_), nType(nType_), nVersion(nVersion_) {} | ||||
template <typename T> OverrideStream<Stream> &operator<<(const T &obj) { | template <typename T> OverrideStream<Stream> &operator<<(const T &obj) { | ||||
// Serialize to this stream | // Serialize to this stream | ||||
::Serialize(*this, obj); | ::Serialize(*this, obj); | ||||
return (*this); | return (*this); | ||||
} | } | ||||
template <typename T> OverrideStream<Stream> &operator>>(T &obj) { | template <typename T> OverrideStream<Stream> &operator>>(T &&obj) { | ||||
// Unserialize from this stream | // Unserialize from this stream | ||||
::Unserialize(*this, obj); | ::Unserialize(*this, obj); | ||||
return (*this); | return (*this); | ||||
} | } | ||||
void write(const char *pch, size_t nSize) { stream->write(pch, nSize); } | void write(const char *pch, size_t nSize) { stream->write(pch, nSize); } | ||||
void read(char *pch, size_t nSize) { stream->read(pch, nSize); } | void read(char *pch, size_t nSize) { stream->read(pch, nSize); } | ||||
▲ Show 20 Lines • Show All 379 Lines • ▼ Show 20 Lines | public: | ||||
} | } | ||||
template <typename T> CDataStream &operator<<(const T &obj) { | template <typename T> CDataStream &operator<<(const T &obj) { | ||||
// Serialize to this stream | // Serialize to this stream | ||||
::Serialize(*this, obj); | ::Serialize(*this, obj); | ||||
return (*this); | return (*this); | ||||
} | } | ||||
template <typename T> CDataStream &operator>>(T &obj) { | template <typename T> CDataStream &operator>>(T &&obj) { | ||||
// Unserialize from this stream | // Unserialize from this stream | ||||
::Unserialize(*this, obj); | ::Unserialize(*this, obj); | ||||
return (*this); | return (*this); | ||||
} | } | ||||
void GetAndClear(CSerializeData &d) { | void GetAndClear(CSerializeData &d) { | ||||
d.insert(d.end(), begin(), end()); | d.insert(d.end(), begin(), end()); | ||||
clear(); | clear(); | ||||
▲ Show 20 Lines • Show All 215 Lines • ▼ Show 20 Lines | template <typename T> CAutoFile &operator<<(const T &obj) { | ||||
// Serialize to this stream | // Serialize to this stream | ||||
if (!file) | if (!file) | ||||
throw std::ios_base::failure( | throw std::ios_base::failure( | ||||
"CAutoFile::operator<<: file handle is nullptr"); | "CAutoFile::operator<<: file handle is nullptr"); | ||||
::Serialize(*this, obj); | ::Serialize(*this, obj); | ||||
return (*this); | return (*this); | ||||
} | } | ||||
template <typename T> CAutoFile &operator>>(T &obj) { | template <typename T> CAutoFile &operator>>(T &&obj) { | ||||
// Unserialize from this stream | // Unserialize from this stream | ||||
if (!file) | if (!file) | ||||
throw std::ios_base::failure( | throw std::ios_base::failure( | ||||
"CAutoFile::operator>>: file handle is nullptr"); | "CAutoFile::operator>>: file handle is nullptr"); | ||||
::Unserialize(*this, obj); | ::Unserialize(*this, obj); | ||||
return (*this); | return (*this); | ||||
} | } | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | public: | ||||
// Prevent reading beyond a certain position. No argument removes the limit. | // Prevent reading beyond a certain position. No argument removes the limit. | ||||
bool SetLimit(uint64_t nPos = (uint64_t)(-1)) { | bool SetLimit(uint64_t nPos = (uint64_t)(-1)) { | ||||
if (nPos < nReadPos) return false; | if (nPos < nReadPos) return false; | ||||
nReadLimit = nPos; | nReadLimit = nPos; | ||||
return true; | return true; | ||||
} | } | ||||
template <typename T> CBufferedFile &operator>>(T &obj) { | template <typename T> CBufferedFile &operator>>(T &&obj) { | ||||
// Unserialize from this stream | // Unserialize from this stream | ||||
::Unserialize(*this, obj); | ::Unserialize(*this, obj); | ||||
return (*this); | return (*this); | ||||
} | } | ||||
// search for a given byte in the stream, and remain positioned on it | // search for a given byte in the stream, and remain positioned on it | ||||
void FindByte(char ch) { | void FindByte(char ch) { | ||||
while (true) { | while (true) { | ||||
if (nReadPos == nSrcPos) Fill(); | if (nReadPos == nSrcPos) Fill(); | ||||
if (vchBuf[nReadPos % vchBuf.size()] == ch) break; | if (vchBuf[nReadPos % vchBuf.size()] == ch) break; | ||||
nReadPos++; | nReadPos++; | ||||
} | } | ||||
} | } | ||||
}; | }; | ||||
#endif // BITCOIN_STREAMS_H | #endif // BITCOIN_STREAMS_H |