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