| 156 | /** Reads data from an underlying stream, while hashing the read data. */ |
| 157 | template<typename Source> |
| 158 | class CHashVerifier : public CHashWriter |
| 159 | { |
| 160 | private: |
| 161 | Source* source; |
| 162 | |
| 163 | public: |
| 164 | explicit CHashVerifier(Source* source_) : CHashWriter(source_->GetType(), source_->GetVersion()), source(source_) {} |
| 165 | |
| 166 | void read(Span<std::byte> dst) |
| 167 | { |
| 168 | source->read(dst); |
| 169 | this->write(dst); |
| 170 | } |
| 171 | |
| 172 | void ignore(size_t nSize) |
| 173 | { |
| 174 | std::byte data[1024]; |
| 175 | while (nSize > 0) { |
| 176 | size_t now = std::min<size_t>(nSize, 1024); |
| 177 | read({data, now}); |
| 178 | nSize -= now; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | template<typename T> |
| 183 | CHashVerifier<Source>& operator>>(T&& obj) |
| 184 | { |
| 185 | // Unserialize from this stream |
| 186 | ::Unserialize(*this, obj); |
| 187 | return (*this); |
| 188 | } |
| 189 | }; |
| 190 | |
| 191 | /** Writes data to an underlying source stream, while hashing the written data. */ |
| 192 | template <typename Source> |
nothing calls this directly
no test coverage detected