| 41 | } |
| 42 | |
| 43 | bool BinFileReader::Read(std::string* key, std::string* value) { |
| 44 | CHECK(fdat_.is_open()) << "File not open!"; |
| 45 | char magic[4]; |
| 46 | int smagic = sizeof(magic); |
| 47 | if (!PrepareNextField(smagic)) return false; |
| 48 | memcpy(magic, buf_ + offset_, smagic); |
| 49 | offset_ += smagic; |
| 50 | |
| 51 | if (magic[0] == kMagicWord[0] && magic[1] == kMagicWord[1]) { |
| 52 | if (magic[2] != 0 && magic[2] != 1) |
| 53 | LOG(FATAL) << "File format error: magic word does not match!"; |
| 54 | if (magic[2] == 1) |
| 55 | if (!ReadField(key)) return false; |
| 56 | if (!ReadField(value)) return false; |
| 57 | } |
| 58 | else { |
| 59 | LOG(FATAL) << "File format error: magic word does not match!"; |
| 60 | } |
| 61 | return true; |
| 62 | } |
| 63 | |
| 64 | int BinFileReader::Count() { |
| 65 | std::ifstream fin(path_, std::ios::in | std::ios::binary); |
nothing calls this directly
no outgoing calls
no test coverage detected