| 115 | ValdiArchiveBuilder::ValdiArchiveBuilder() = default; |
| 116 | |
| 117 | void ValdiArchiveBuilder::addEntry(const ValdiArchiveEntry& entry) { |
| 118 | _moduleData.reserve(_moduleData.size() + entry.dataLength + entry.filePath.length() + sizeof(uint32_t) * 2); |
| 119 | |
| 120 | auto filenameLength = static_cast<uint32_t>(entry.filePath.length()); |
| 121 | auto dataLength = static_cast<uint32_t>(entry.dataLength); |
| 122 | |
| 123 | auto filenamePaddingLength = computePadding(entry.filePath.length()); |
| 124 | auto dataPaddingLength = computePadding(entry.dataLength); |
| 125 | if (filenamePaddingLength > 0) { |
| 126 | filenameLength |= kPaddingBit; |
| 127 | } |
| 128 | if (dataPaddingLength > 0) { |
| 129 | dataLength |= kPaddingBit; |
| 130 | } |
| 131 | _moduleData.append(reinterpret_cast<Byte*>(&filenameLength), reinterpret_cast<Byte*>(&filenameLength + 1)); |
| 132 | _moduleData.append(entry.filePath.getCStr(), entry.filePath.getCStr() + entry.filePath.length()); |
| 133 | appendPadding(filenamePaddingLength); |
| 134 | |
| 135 | _moduleData.append(reinterpret_cast<Byte*>(&dataLength), reinterpret_cast<Byte*>(&dataLength + 1)); |
| 136 | _moduleData.append(entry.data, entry.data + entry.dataLength); |
| 137 | appendPadding(dataPaddingLength); |
| 138 | } |
| 139 | |
| 140 | void ValdiArchiveBuilder::appendPadding(size_t padding) { |
| 141 | for (size_t i = 0; i < padding; i++) { |