if the buf does not have the next complete field, read data from disk
| 118 | |
| 119 | // if the buf does not have the next complete field, read data from disk |
| 120 | bool BinFileReader::PrepareNextField(int size) { |
| 121 | if (offset_ + size > bufsize_) { |
| 122 | bufsize_ -= offset_; |
| 123 | memcpy(buf_, buf_ + offset_, bufsize_); |
| 124 | offset_ = 0; |
| 125 | if (fdat_.eof()) { |
| 126 | return false; |
| 127 | } else { |
| 128 | fdat_.read(buf_ + bufsize_, capacity_ - bufsize_); |
| 129 | bufsize_ += (int) fdat_.gcount(); |
| 130 | CHECK_LE(size, bufsize_) << "Field size is too large: " << size; |
| 131 | } |
| 132 | } |
| 133 | return true; |
| 134 | } |
| 135 | |
| 136 | } // namespace io |
| 137 | } // namespace singa |