-
-
- uint16_t read_integer16(std::ifstream& file) {
-
- uint64_t n = read_integer(file, 2);
- assert(n == (uint16_t)n);
- return (uint16_t)n;
- }
-
-
- uint64_t read_integer64(std::ifstream& file) {
-
- return read_integer(file, 8);
- }
-
-
- uint64_t read_integer(std::ifstream& file, int size) {
-
- char buf[8];
- file.read(buf, size);
-
- if (!file.good())
- {
- std::cerr << "Failed to read " << size << " bytes from book file" << std::endl;
- file.close();
- exit(EXIT_FAILURE);
- }
-
- // Numbers are stored on disk in big endian format
- uint64_t n = 0ULL;
- for (int i = 0; i < size; i++)
- n = (n << 8) + (unsigned char)buf[i];
-
- return n;
- }