MCPcopy Create free account
hub / github.com/assimp/assimp / WriteBinaryDump

Method WriteBinaryDump

code/AssetLib/Assbin/AssbinFileWriter.cpp:735–820  ·  view source on GitHub ↗

----------------------------------------------------------------------------------- Write a binary model dump

Source from the content-addressed store, hash-verified

733 // -----------------------------------------------------------------------------------
734 // Write a binary model dump
735 void WriteBinaryDump(const char *pFile, const char *cmd, IOSystem *pIOSystem, const aiScene *pScene) {
736 IOStream *out = pIOSystem->Open(pFile, "wb");
737 if (!out)
738 throw std::runtime_error("Unable to open output file " + std::string(pFile) + '\n');
739
740 auto CloseIOStream = [&]() {
741 if (out) {
742 pIOSystem->Close(out);
743 out = nullptr; // Ensure this is only done once.
744 }
745 };
746
747 try {
748 time_t tt = time(nullptr);
749#if _WIN32
750 tm *p = gmtime(&tt);
751#else
752 struct tm now;
753 tm *p = gmtime_r(&tt, &now);
754#endif
755
756 // header
757 char s[64];
758 memset(s, 0, 64);
759#if _MSC_VER >= 1400
760 sprintf_s(s, "ASSIMP.binary-dump.%s", asctime(p));
761#else
762 ai_snprintf(s, 64, "ASSIMP.binary-dump.%s", asctime(p));
763#endif
764 out->Write(s, 44, 1);
765 // == 44 bytes
766
767 Write<unsigned int>(out, ASSBIN_VERSION_MAJOR);
768 Write<unsigned int>(out, ASSBIN_VERSION_MINOR);
769 Write<unsigned int>(out, aiGetVersionRevision());
770 Write<unsigned int>(out, aiGetCompileFlags());
771 Write<uint16_t>(out, shortened);
772 Write<uint16_t>(out, compressed);
773 // == 20 bytes
774
775 char buff[256] = { 0 };
776 ai_snprintf(buff, 256, "%s", pFile);
777 out->Write(buff, sizeof(char), 256);
778
779 memset(buff, 0, sizeof(buff));
780 ai_snprintf(buff, 128, "%s", cmd);
781 out->Write(buff, sizeof(char), 128);
782
783 // leave 64 bytes free for future extensions
784 memset(buff, 0xcd, 64);
785 out->Write(buff, sizeof(char), 64);
786 // == 435 bytes
787
788 // ==== total header size: 512 bytes
789 ai_assert(out->Tell() == ASSBIN_HEADER_LENGTH);
790
791 // Up to here the data is uncompressed. For compressed files, the rest
792 // is compressed using standard DEFLATE from zlib.

Callers 1

DumpSceneToAssbinFunction · 0.80

Calls 10

ai_snprintfFunction · 0.85
aiGetVersionRevisionFunction · 0.85
aiGetCompileFlagsFunction · 0.85
compressBoundFunction · 0.85
compress2Function · 0.85
GetBufferPointerMethod · 0.80
OpenMethod · 0.45
CloseMethod · 0.45
WriteMethod · 0.45
TellMethod · 0.45

Tested by

no test coverage detected