@@ -545,10 +545,8 @@ bool readBinaryToJson(const std::string& inFile, json& output)
545545 DEBUG_LOG ((" String ID %u: '%s'" , stringID, str.c_str ()));
546546 }
547547 }
548- else
549- {
550- fseek (fp, 0 , SEEK_SET);
551- }
548+
549+ fseek (fp, 0 , SEEK_SET);
552550
553551 FileInputStream stream (fp);
554552 DataChunkInput chunkInput (&stream);
@@ -853,59 +851,61 @@ bool writeJsonToBinary(const json& input, const std::string& outFile)
853851 return false ;
854852 }
855853
856- FileOutputStream stream (fp);
857- DataChunkOutput chunkOutput (&stream);
858-
859- if (input.contains (" stringTable" ))
860854 {
861- std::vector<std::string> stringTable = input[" stringTable" ].get <std::vector<std::string>>();
862-
863- for (size_t i = 0 ; i < stringTable.size (); i++)
864- {
865- if (!stringTable[i].empty ())
866- {
867- chunkOutput.m_contents .allocateID (stringTable[i]);
868- }
869- }
870-
871- if (input.contains (" chunks" ))
855+ FileOutputStream stream (fp);
856+ DataChunkOutput chunkOutput (&stream);
857+
858+ if (input.contains (" stringTable" ))
872859 {
873- for (const auto & chunkEntry : input[" chunks" ])
860+ std::vector<std::string> stringTable = input[" stringTable" ].get <std::vector<std::string>>();
861+
862+ for (size_t i = 0 ; i < stringTable.size (); i++)
874863 {
875- std::string chunkTypeName = chunkEntry.value (" type" , " " );
876- if (chunkTypeName.empty ())
864+ if (!stringTable[i].empty ())
877865 {
878- uint32_t chunkID = chunkEntry.value (" id" , 0 );
879- if (chunkID < stringTable.size ())
880- chunkTypeName = stringTable[chunkID];
866+ chunkOutput.m_contents .allocateID (stringTable[i]);
881867 }
882-
883- uint16_t outerVersion = chunkEntry.value (" version" , 1 );
884-
885- if (chunkTypeName.empty ())
886- chunkTypeName = " UNKNOWN" ;
887-
888- chunkOutput.openDataChunk (chunkTypeName.c_str (), outerVersion);
889-
890- if (chunkEntry.contains (" parsed" ))
891- {
892- const json& parsed = chunkEntry[" parsed" ];
893- std::vector<uint8_t > innerData = serializeChunk (parsed, stringTable);
894- if (!innerData.empty ())
895- chunkOutput.writeArrayOfBytes ((const char *)innerData.data (), innerData.size ());
896- }
897- else if (chunkEntry.contains (" rawData" ))
868+ }
869+
870+ if (input.contains (" chunks" ))
871+ {
872+ for (const auto & chunkEntry : input[" chunks" ])
898873 {
899- std::vector<uint8_t > innerData = chunkEntry[" rawData" ].get <std::vector<uint8_t >>();
900- if (!innerData.empty ())
901- chunkOutput.writeArrayOfBytes ((const char *)innerData.data (), innerData.size ());
874+ std::string chunkTypeName = chunkEntry.value (" type" , " " );
875+ if (chunkTypeName.empty ())
876+ {
877+ uint32_t chunkID = chunkEntry.value (" id" , 0 );
878+ if (chunkID < stringTable.size ())
879+ chunkTypeName = stringTable[chunkID];
880+ }
881+
882+ uint16_t outerVersion = chunkEntry.value (" version" , 1 );
883+
884+ if (chunkTypeName.empty ())
885+ chunkTypeName = " UNKNOWN" ;
886+
887+ chunkOutput.openDataChunk (chunkTypeName.c_str (), outerVersion);
888+
889+ if (chunkEntry.contains (" parsed" ))
890+ {
891+ const json& parsed = chunkEntry[" parsed" ];
892+ std::vector<uint8_t > innerData = serializeChunk (parsed, stringTable);
893+ if (!innerData.empty ())
894+ chunkOutput.writeArrayOfBytes ((const char *)innerData.data (), innerData.size ());
895+ }
896+ else if (chunkEntry.contains (" rawData" ))
897+ {
898+ std::vector<uint8_t > innerData = chunkEntry[" rawData" ].get <std::vector<uint8_t >>();
899+ if (!innerData.empty ())
900+ chunkOutput.writeArrayOfBytes ((const char *)innerData.data (), innerData.size ());
901+ }
902+
903+ chunkOutput.closeDataChunk ();
902904 }
903-
904- chunkOutput.closeDataChunk ();
905905 }
906906 }
907907 }
908-
908+
909909 fclose (fp);
910910 DEBUG_LOG ((" Successfully wrote binary SCB file" ));
911911 return true ;
0 commit comments