| 446 | } |
| 447 | |
| 448 | inline std::string read_header(std::istream &istream) { |
| 449 | // check magic bytes an version number |
| 450 | version_t version = read_magic(istream); |
| 451 | |
| 452 | uint32_t header_length; |
| 453 | if (version == version_t{1, 0}) { |
| 454 | uint8_t header_len_le16[2]; |
| 455 | istream.read(reinterpret_cast<char *>(header_len_le16), 2); |
| 456 | header_length = (header_len_le16[0] << 0) | (header_len_le16[1] << 8); |
| 457 | |
| 458 | if ((magic_string_length + 2 + 2 + header_length) % 16 != 0) { |
| 459 | // TODO(llohse): display warning |
| 460 | } |
| 461 | } else if (version == version_t{2, 0}) { |
| 462 | uint8_t header_len_le32[4]; |
| 463 | istream.read(reinterpret_cast<char *>(header_len_le32), 4); |
| 464 | |
| 465 | header_length = (header_len_le32[0] << 0) | (header_len_le32[1] << 8) |
| 466 | | (header_len_le32[2] << 16) | (header_len_le32[3] << 24); |
| 467 | |
| 468 | if ((magic_string_length + 2 + 4 + header_length) % 16 != 0) { |
| 469 | // TODO(llohse): display warning |
| 470 | } |
| 471 | } else { |
| 472 | throw std::runtime_error("unsupported file format version"); |
| 473 | } |
| 474 | |
| 475 | auto buf_v = std::vector<char>(header_length); |
| 476 | istream.read(buf_v.data(), header_length); |
| 477 | std::string header(buf_v.data(), header_length); |
| 478 | |
| 479 | return header; |
| 480 | } |
| 481 | |
| 482 | inline ndarray_len_t comp_size(const std::vector <ndarray_len_t> &shape) { |
| 483 | ndarray_len_t size = 1; |
no test coverage detected