| 494 | } |
| 495 | |
| 496 | inline std::string read_header(std::istream& istream) { |
| 497 | // check magic bytes an version number |
| 498 | unsigned char v_major, v_minor; |
| 499 | read_magic(istream, v_major, v_minor); |
| 500 | |
| 501 | uint32_t header_length = 0; |
| 502 | if (v_major == 1 && v_minor == 0) { |
| 503 | char header_len_le16[2]; |
| 504 | istream.read(header_len_le16, 2); |
| 505 | header_length = (header_len_le16[0] << 0) | (header_len_le16[1] << 8); |
| 506 | |
| 507 | if ((magic_string_length + 2 + 2 + header_length) % 16 != 0) { |
| 508 | // TODO: display warning |
| 509 | } |
| 510 | } else if (v_major == 2 && v_minor == 0) { |
| 511 | char header_len_le32[4]; |
| 512 | istream.read(header_len_le32, 4); |
| 513 | |
| 514 | header_length = (header_len_le32[0] << 0) | (header_len_le32[1] << 8) | |
| 515 | (header_len_le32[2] << 16) | (header_len_le32[3] << 24); |
| 516 | |
| 517 | if ((magic_string_length + 2 + 4 + header_length) % 16 != 0) { |
| 518 | // TODO: display warning |
| 519 | } |
| 520 | } else { |
| 521 | fprintf(stderr, "unsupported file format version"); |
| 522 | } |
| 523 | |
| 524 | auto buf_v = std::vector<char>(); |
| 525 | buf_v.reserve(header_length); |
| 526 | istream.read(buf_v.data(), header_length); |
| 527 | std::string header(buf_v.data(), header_length); |
| 528 | |
| 529 | return header; |
| 530 | } |
| 531 | |
| 532 | inline ndarray_len_t comp_size(const std::vector<ndarray_len_t>& shape) { |
| 533 | ndarray_len_t size = 1; |
no test coverage detected