| 215 | } |
| 216 | |
| 217 | Status BaseSequenceScanner::ReadSync() { |
| 218 | DCHECK(!eos_); |
| 219 | if (stream_->eosr()) { |
| 220 | // Either we're at the end of file or the next sync marker is completely in the next |
| 221 | // scan range. |
| 222 | eos_ = true; |
| 223 | } else { |
| 224 | // Not at end of scan range or file - we expect there to be another sync marker, which |
| 225 | // is either followed by another block or the end of the file. |
| 226 | uint8_t* hash; |
| 227 | int64_t out_len; |
| 228 | bool success = stream_->GetBytes(SYNC_HASH_SIZE, &hash, &out_len, &parse_status_); |
| 229 | if (!success) return parse_status_; |
| 230 | if (out_len != SYNC_HASH_SIZE) { |
| 231 | return Status(Substitute("Hit end of stream after reading $0 bytes of $1-byte " |
| 232 | "synchronization marker", out_len, SYNC_HASH_SIZE)); |
| 233 | } else if (memcmp(hash, header_->sync, SYNC_HASH_SIZE) != 0) { |
| 234 | stringstream ss; |
| 235 | ss << "Bad synchronization marker" << endl |
| 236 | << " Expected: '" |
| 237 | << ReadWriteUtil::HexDump(header_->sync, SYNC_HASH_SIZE) << "'" << endl |
| 238 | << " Actual: '" |
| 239 | << ReadWriteUtil::HexDump(hash, SYNC_HASH_SIZE) << "'"; |
| 240 | return Status(ss.str()); |
| 241 | } |
| 242 | // If we read the sync marker at end of file then we're done! |
| 243 | eos_ = stream_->eof(); |
| 244 | ++num_syncs_; |
| 245 | block_start_ = stream_->file_offset(); |
| 246 | } |
| 247 | total_block_size_ += stream_->file_offset() - block_start_; |
| 248 | return Status::OK(); |
| 249 | } |
| 250 | |
| 251 | int BaseSequenceScanner::FindSyncBlock(const uint8_t* buffer, int buffer_len, |
| 252 | const uint8_t* sync, int sync_len) { |
nothing calls this directly
no test coverage detected