| 773 | } |
| 774 | |
| 775 | void ReadWritePackedObjectsChunk(OrcaStream& os) |
| 776 | { |
| 777 | static constexpr uint8_t kDescriptorDat = 0; |
| 778 | static constexpr uint8_t kDescriptorParkObj = 1; |
| 779 | |
| 780 | if (os.getMode() == OrcaStream::Mode::writing && ExportObjectsList.empty()) |
| 781 | { |
| 782 | // Do not emit chunk if there are no packed objects |
| 783 | return; |
| 784 | } |
| 785 | |
| 786 | os.readWriteChunk(ParkFileChunkType::packedObjects, [this](OrcaStream::ChunkStream& cs) { |
| 787 | if (cs.getMode() == OrcaStream::Mode::reading) |
| 788 | { |
| 789 | auto& objRepository = GetContext()->GetObjectRepository(); |
| 790 | auto numObjects = cs.read<uint32_t>(); |
| 791 | for (uint32_t i = 0; i < numObjects; i++) |
| 792 | { |
| 793 | auto type = cs.read<uint8_t>(); |
| 794 | if (type == kDescriptorDat) |
| 795 | { |
| 796 | RCTObjectEntry entry; |
| 797 | cs.read(&entry, sizeof(entry)); |
| 798 | auto size = cs.read<uint32_t>(); |
| 799 | std::vector<uint8_t> data; |
| 800 | data.resize(size); |
| 801 | cs.read(data.data(), data.size()); |
| 802 | |
| 803 | auto legacyIdentifier = entry.GetName(); |
| 804 | if (objRepository.FindObjectLegacy(legacyIdentifier) == nullptr) |
| 805 | { |
| 806 | objRepository.AddObjectFromFile( |
| 807 | ObjectGeneration::DAT, legacyIdentifier, data.data(), data.size()); |
| 808 | } |
| 809 | } |
| 810 | else if (type == kDescriptorParkObj) |
| 811 | { |
| 812 | auto identifier = cs.read<std::string>(); |
| 813 | auto size = cs.read<uint32_t>(); |
| 814 | std::vector<uint8_t> data; |
| 815 | data.resize(size); |
| 816 | cs.read(data.data(), data.size()); |
| 817 | if (objRepository.FindObject(identifier) == nullptr) |
| 818 | { |
| 819 | objRepository.AddObjectFromFile(ObjectGeneration::JSON, identifier, data.data(), data.size()); |
| 820 | } |
| 821 | } |
| 822 | else |
| 823 | { |
| 824 | throw std::runtime_error("Unsupported packed object"); |
| 825 | } |
| 826 | } |
| 827 | } |
| 828 | else |
| 829 | { |
| 830 | auto& stream = cs.getStream(); |
| 831 | auto countPosition = stream.GetPosition(); |
| 832 |
nothing calls this directly
no test coverage detected