------------------------------------------------------------------------------------------------ read binary data array, assume cursor points to the 'compression mode' field (i.e. behind the header)
| 530 | // ------------------------------------------------------------------------------------------------ |
| 531 | // read binary data array, assume cursor points to the 'compression mode' field (i.e. behind the header) |
| 532 | void ReadBinaryDataArray(char type, uint32_t count, const char*& data, const char* end, |
| 533 | std::vector<char>& buff, const Element& /*el*/) { |
| 534 | BE_NCONST uint32_t encmode = SafeParse<uint32_t>(data, end); |
| 535 | AI_SWAP4(encmode); |
| 536 | data += 4; |
| 537 | |
| 538 | // next comes the compressed length |
| 539 | BE_NCONST uint32_t comp_len = SafeParse<uint32_t>(data, end); |
| 540 | AI_SWAP4(comp_len); |
| 541 | data += 4; |
| 542 | |
| 543 | ai_assert(data + comp_len == end); |
| 544 | |
| 545 | // determine the length of the uncompressed data by looking at the type signature |
| 546 | uint32_t stride = 0; |
| 547 | switch(type) |
| 548 | { |
| 549 | case 'f': |
| 550 | case 'i': |
| 551 | stride = 4; |
| 552 | break; |
| 553 | |
| 554 | case 'd': |
| 555 | case 'l': |
| 556 | stride = 8; |
| 557 | break; |
| 558 | |
| 559 | default: |
| 560 | ai_assert(false); |
| 561 | }; |
| 562 | |
| 563 | const uint32_t full_length = stride * count; |
| 564 | buff.resize(full_length); |
| 565 | |
| 566 | if(encmode == 0) { |
| 567 | ai_assert(full_length == comp_len); |
| 568 | |
| 569 | // plain data, no compression |
| 570 | std::copy(data, end, buff.begin()); |
| 571 | } |
| 572 | else if(encmode == 1) { |
| 573 | // zlib/deflate, next comes ZIP head (0x78 0x01) |
| 574 | // see http://www.ietf.org/rfc/rfc1950.txt |
| 575 | Compression compress; |
| 576 | if (compress.open(Compression::Format::Binary, Compression::FlushMode::Finish, 0)) { |
| 577 | compress.decompress(data, comp_len, buff); |
| 578 | compress.close(); |
| 579 | } |
| 580 | } |
| 581 | #ifdef ASSIMP_BUILD_DEBUG |
| 582 | else { |
| 583 | // runtime check for this happens at tokenization stage |
| 584 | ai_assert(false); |
| 585 | } |
| 586 | #endif |
| 587 | |
| 588 | data += comp_len; |
| 589 | ai_assert(data == end); |
no test coverage detected