activity_sdk_topology_inventory.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. #include <algorithm>
  2. #include <array>
  3. #include <limits>
  4. #include <string>
  5. #include <string_view>
  6. #include <utility>
  7. #include <vector>
  8. #include "../../../middleware/content/packages/tables/scenario_reader.h"
  9. #include "../../../state/activity_sdk/format.h"
  10. #include "activity_sdk_topology_inventory_internal.h"
  11. namespace sunrise::client::content::activity::sdk_generation::topology_inventory {
  12. using detail::build_object;
  13. using detail::build_occurrence;
  14. using detail::format_text;
  15. using detail::kActivityTopologyJoinMask;
  16. using detail::merge_object;
  17. using detail::valid_open_prefix;
  18. using detail::valid_registry_field;
  19. namespace {
  20. namespace catalog = state::build_data::scriptables;
  21. namespace format = state::activity_sdk::format;
  22. namespace tables = middleware::content::packages::tables;
  23. /** One prior object replacement prepared before the scenario commits. */
  24. struct ObjectUpdate final {
  25. std::size_t row{};
  26. Object value{};
  27. };
  28. /** Copies one bounded byte string and always retains a trailing zero. */
  29. [[nodiscard]] bool copy_text(std::string_view source, Text& output) noexcept {
  30. output = {};
  31. if (source.size() >= output.value.size()
  32. || source.size() > (std::numeric_limits<std::uint16_t>::max)()) {
  33. return false;
  34. }
  35. std::copy(source.begin(), source.end(), output.value.begin());
  36. output.length = static_cast<std::uint16_t>(source.size());
  37. return true;
  38. }
  39. /** Returns a view only when the owned length remains inside its fixed storage. */
  40. [[nodiscard]] bool text_view_impl(const Text& source, std::string_view& output) noexcept {
  41. output = {};
  42. if (source.length >= source.value.size()) {
  43. return false;
  44. }
  45. output = std::string_view(source.value.data(), source.length);
  46. return true;
  47. }
  48. /** Uses unsigned UTF-8 bytes, which is the canonical string order. */
  49. [[nodiscard]] bool byte_less_impl(std::string_view left, std::string_view right) noexcept {
  50. return std::lexicographical_compare(
  51. left.begin(), left.end(), right.begin(), right.end(), [](char a, char b) noexcept {
  52. return static_cast<unsigned char>(a) < static_cast<unsigned char>(b);
  53. });
  54. }
  55. /** Rejects malformed UTF-8 and embedded zero bytes before string storage. */
  56. [[nodiscard]] bool valid_utf8_impl(std::string_view value) noexcept {
  57. std::size_t index = 0;
  58. while (index < value.size()) {
  59. const auto first = static_cast<unsigned char>(value[index]);
  60. if (first == 0) {
  61. return false;
  62. }
  63. if (first <= 0x7FU) {
  64. ++index;
  65. continue;
  66. }
  67. if (first >= 0xC2U && first <= 0xDFU) {
  68. if (index + 1 >= value.size()) {
  69. return false;
  70. }
  71. const auto second = static_cast<unsigned char>(value[index + 1]);
  72. if (second < 0x80U || second > 0xBFU) {
  73. return false;
  74. }
  75. index += 2;
  76. continue;
  77. }
  78. if (first >= 0xE0U && first <= 0xEFU) {
  79. if (index + 2 >= value.size()) {
  80. return false;
  81. }
  82. const auto second = static_cast<unsigned char>(value[index + 1]);
  83. const auto third = static_cast<unsigned char>(value[index + 2]);
  84. const bool secondValid = first == 0xE0U ? second >= 0xA0U && second <= 0xBFU
  85. : first == 0xEDU ? second >= 0x80U && second <= 0x9FU
  86. : second >= 0x80U && second <= 0xBFU;
  87. if (!secondValid || third < 0x80U || third > 0xBFU) {
  88. return false;
  89. }
  90. index += 3;
  91. continue;
  92. }
  93. if (first >= 0xF0U && first <= 0xF4U) {
  94. if (index + 3 >= value.size()) {
  95. return false;
  96. }
  97. const auto second = static_cast<unsigned char>(value[index + 1]);
  98. const auto third = static_cast<unsigned char>(value[index + 2]);
  99. const auto fourth = static_cast<unsigned char>(value[index + 3]);
  100. const bool secondValid = first == 0xF0U ? second >= 0x90U && second <= 0xBFU
  101. : first == 0xF4U ? second >= 0x80U && second <= 0x8FU
  102. : second >= 0x80U && second <= 0xBFU;
  103. if (!secondValid || third < 0x80U || third > 0xBFU || fourth < 0x80U
  104. || fourth > 0xBFU) {
  105. return false;
  106. }
  107. index += 4;
  108. continue;
  109. }
  110. return false;
  111. }
  112. return true;
  113. }
  114. /** Returns the compact FNV-1 hash used by package-inline names. */
  115. [[nodiscard]] std::uint32_t content_hash(std::string_view value) noexcept {
  116. std::uint32_t hash = 2166136261U;
  117. for (const unsigned char byte : value) {
  118. hash = (hash * 16777619U) ^ byte;
  119. }
  120. return hash;
  121. }
  122. /** Finds one scenario index in the inventory's strict tag order. */
  123. [[nodiscard]] std::uint32_t scenario_index(const Snapshot& output, std::uint32_t tag) noexcept {
  124. const auto found = std::lower_bound(
  125. output.scenarios.begin(), output.scenarios.end(), tag, [](const Scenario& row, auto value) {
  126. return row.tag < value;
  127. });
  128. return found != output.scenarios.end() && found->tag == tag
  129. ? static_cast<std::uint32_t>(found - output.scenarios.begin())
  130. : catalog::kNoRow;
  131. }
  132. /** Returns one exact value from an inline-name byte bank. */
  133. template <typename Row>
  134. [[nodiscard]] bool inline_value(const Row& row,
  135. const std::vector<std::byte>& bytes,
  136. std::string_view& output) noexcept {
  137. output = {};
  138. const std::size_t first = row.firstByte;
  139. if (first > bytes.size() || row.byteCount > bytes.size() - first) {
  140. return false;
  141. }
  142. output = std::string_view(reinterpret_cast<const char*>(bytes.data() + first), row.byteCount);
  143. return true;
  144. }
  145. /** Compares two inline-name identities by hash and unsigned UTF-8 bytes. */
  146. template <typename LeftRow, typename RightRow>
  147. [[nodiscard]] int compare_inline(const LeftRow& left,
  148. const std::vector<std::byte>& leftBytes,
  149. const RightRow& right,
  150. const std::vector<std::byte>& rightBytes) noexcept {
  151. if (left.hash != right.hash) {
  152. return left.hash < right.hash ? -1 : 1;
  153. }
  154. std::string_view leftValue{};
  155. std::string_view rightValue{};
  156. if (!inline_value(left, leftBytes, leftValue) || !inline_value(right, rightBytes, rightValue)) {
  157. return 2;
  158. }
  159. if (leftValue == rightValue) {
  160. return 0;
  161. }
  162. return byte_less_impl(leftValue, rightValue) ? -1 : 1;
  163. }
  164. /** Checks one sorted, unique, contiguous package-inline bank. */
  165. template <typename Row>
  166. [[nodiscard]] bool valid_inline_bank_impl(const std::vector<Row>& rows,
  167. const std::vector<std::byte>& bytes) noexcept {
  168. std::size_t nextByte = 0;
  169. for (std::size_t index = 0; index < rows.size(); ++index) {
  170. const Row& row = rows[index];
  171. std::string_view value{};
  172. if (row.firstByte != nextByte || row.byteCount == 0
  173. || row.byteCount > catalog::kInlineNameMaximumBytes || !inline_value(row, bytes, value)
  174. || !valid_utf8_impl(value) || content_hash(value) != row.hash) {
  175. return false;
  176. }
  177. if (index != 0 && compare_inline(rows[index - 1], bytes, row, bytes) >= 0) {
  178. return false;
  179. }
  180. nextByte += row.byteCount;
  181. }
  182. return nextByte == bytes.size();
  183. }
  184. /** Collects only new inline values while the final bank order remains open. */
  185. [[nodiscard]] bool collect_inline_names(const catalog::Snapshot& source,
  186. const Snapshot& current,
  187. std::vector<std::string>& output,
  188. std::size_t& addedBytes) {
  189. output.clear();
  190. addedBytes = 0;
  191. if (!valid_inline_bank_impl(source.inlineNameCandidates, source.inlineNameBytes)
  192. || current.accumulator.inlineNames.size() > format::kAbsentIndex
  193. || current.accumulator.inlineNameBytes > format::kAbsentIndex) {
  194. return false;
  195. }
  196. output.reserve(source.inlineNameCandidates.size());
  197. for (const catalog::InlineNameCandidate& row : source.inlineNameCandidates) {
  198. std::string_view value{};
  199. if (!inline_value(row, source.inlineNameBytes, value)) {
  200. return false;
  201. }
  202. std::string owned(value);
  203. if (current.accumulator.inlineNames.contains(owned)) {
  204. continue;
  205. }
  206. if (output.size() >= format::kAbsentIndex - current.accumulator.inlineNames.size()
  207. || addedBytes > format::kAbsentIndex - current.accumulator.inlineNameBytes
  208. || value.size()
  209. > format::kAbsentIndex - current.accumulator.inlineNameBytes - addedBytes) {
  210. return false;
  211. }
  212. addedBytes += value.size();
  213. output.push_back(std::move(owned));
  214. }
  215. return true;
  216. }
  217. /** Validates one source state and copies every v9 topology scalar. */
  218. [[nodiscard]] bool append_state(const catalog::State& input,
  219. std::uint32_t scenarioTag,
  220. std::uint32_t scenarioIndex,
  221. std::uint32_t bubbleIndex,
  222. std::uint32_t bubbleOrdinal,
  223. std::uint32_t stateOrdinal,
  224. std::vector<State>& output) {
  225. if (!input.resolved || input.bubbleRow != bubbleOrdinal || input.index != stateOrdinal
  226. || input.entryTag == 0 || input.entryTag == format::kAbsentIndex || input.registryTag == 0
  227. || input.registryTag == format::kAbsentIndex
  228. || input.sliceSetIndex % tables::kSliceSetIndexFactor != 0) {
  229. return false;
  230. }
  231. const std::uint32_t entryIndex = input.sliceSetIndex / tables::kSliceSetIndexFactor;
  232. if (entryIndex != bubbleOrdinal || output.size() >= format::kAbsentIndex) {
  233. return false;
  234. }
  235. State state{};
  236. state.scenarioIndex = scenarioIndex;
  237. state.bubbleIndex = bubbleIndex;
  238. state.stateOrdinal = stateOrdinal;
  239. state.entryIndex = entryIndex;
  240. state.sliceSetIndex = input.sliceSetIndex;
  241. state.mapBubbleIndex = input.mapBubbleIndex;
  242. state.stateHash = input.stateHash;
  243. state.rawU32At12 = input.rawU32At12;
  244. state.entryTag = input.entryTag;
  245. state.registryTag = input.registryTag;
  246. state.enabled = input.enabled;
  247. if (!format_text(state.id,
  248. "state/%08x/%04x/%04x/%08x",
  249. static_cast<unsigned>(scenarioTag),
  250. static_cast<unsigned>(bubbleOrdinal),
  251. static_cast<unsigned>(stateOrdinal),
  252. static_cast<unsigned>(input.entryTag))
  253. || !format_text(state.entryId, "entry/%08x", static_cast<unsigned>(input.entryTag))
  254. || !format_text(
  255. state.registryId, "registry/%08x", static_cast<unsigned>(input.registryTag))) {
  256. return false;
  257. }
  258. output.push_back(state);
  259. return true;
  260. }
  261. } // namespace
  262. namespace detail {
  263. /** Returns a view only when the owned length remains inside its fixed storage. */
  264. bool text_view(const Text& source, std::string_view& output) noexcept {
  265. return text_view_impl(source, output);
  266. }
  267. /** Uses unsigned UTF-8 bytes, which is the canonical string order. */
  268. bool byte_less(std::string_view left, std::string_view right) noexcept {
  269. return byte_less_impl(left, right);
  270. }
  271. /** Rejects malformed UTF-8 and embedded zero bytes before string storage. */
  272. bool valid_utf8(std::string_view value) noexcept {
  273. return valid_utf8_impl(value);
  274. }
  275. } // namespace detail
  276. /** Starts one deterministic topology build from the complete activity inventory. */
  277. bool begin(const activity_inventory::Snapshot& source, Snapshot& output) noexcept {
  278. output = {};
  279. if (!activity_inventory::validate(source) || source.scenarios.empty()
  280. || source.scenarios.size() >= format::kAbsentIndex
  281. || source.activities.size() >= format::kAbsentIndex) {
  282. return false;
  283. }
  284. try {
  285. Snapshot pending{};
  286. pending.scenarios.reserve(source.scenarios.size());
  287. for (const activity_inventory::ScenarioRoot& sourceScenario : source.scenarios) {
  288. Scenario row{};
  289. row.tag = sourceScenario.tag;
  290. if (!format_text(row.id, "scenario/%08x", static_cast<unsigned>(sourceScenario.tag))
  291. || !copy_text(
  292. std::string_view(sourceScenario.name.data(), sourceScenario.nameLength),
  293. row.name)) {
  294. return false;
  295. }
  296. pending.scenarios.push_back(row);
  297. }
  298. pending.activities.reserve(source.activities.size());
  299. for (const activity_inventory::ActivityVariant& sourceActivity : source.activities) {
  300. Activity row{};
  301. row.activityIndex = sourceActivity.definition.activityIndex;
  302. row.definitionHash = sourceActivity.definition.definitionHash;
  303. if (!format_text(row.id,
  304. "act/%04x/%08x",
  305. static_cast<unsigned>(row.activityIndex),
  306. static_cast<unsigned>(row.definitionHash))
  307. || !copy_text(std::string_view(sourceActivity.definition.internalName.data(),
  308. sourceActivity.definition.internalNameLength),
  309. row.internalName)) {
  310. return false;
  311. }
  312. if (sourceActivity.joinStatus == activity_inventory::JoinStatus::exact) {
  313. row.scenarioIndex = scenario_index(pending, sourceActivity.scenarioTag);
  314. if (row.scenarioIndex == catalog::kNoRow) {
  315. return false;
  316. }
  317. row.exactFlags = kActivityTopologyJoinMask;
  318. }
  319. pending.activities.push_back(row);
  320. }
  321. output = std::move(pending);
  322. return true;
  323. } catch (...) {
  324. output = {};
  325. return false;
  326. }
  327. }
  328. /** Appends the next scenario shard and rejects gaps, repeats, and unsafe source rows. */
  329. bool append(const catalog::Snapshot& source, Snapshot& output) noexcept {
  330. if (!valid_open_prefix(output) || output.nextScenario >= output.scenarios.size()
  331. || source.status != catalog::BuildStatus::ready
  332. || source.coverage != catalog::BuildCoverage::full) {
  333. return false;
  334. }
  335. const Scenario& scenario = output.scenarios[output.nextScenario];
  336. if (source.scenarioTag != scenario.tag || source.scenarioNameLength != scenario.name.length
  337. || !std::equal(source.scenarioName.begin(),
  338. source.scenarioName.begin() + source.scenarioNameLength,
  339. scenario.name.value.begin())
  340. || source.bubbles.size() >= format::kAbsentIndex
  341. || source.states.size() >= format::kAbsentIndex
  342. || source.objects.size() >= format::kAbsentIndex
  343. || output.bubbles.size() > format::kAbsentIndex - source.bubbles.size()
  344. || output.states.size() > format::kAbsentIndex - source.states.size()
  345. || output.occurrences.size() > format::kAbsentIndex - source.objects.size()) {
  346. return false;
  347. }
  348. try {
  349. const std::size_t firstBubble = output.bubbles.size();
  350. const std::size_t firstState = output.states.size();
  351. const std::size_t firstOccurrence = output.occurrences.size();
  352. std::vector<Bubble> pendingBubbles{};
  353. std::vector<State> pendingStates{};
  354. std::vector<Occurrence> pendingOccurrences{};
  355. std::vector<Object> pendingObjects{};
  356. std::vector<std::string> pendingInlineNames{};
  357. std::size_t pendingInlineNameBytes = 0;
  358. if (!collect_inline_names(source, output, pendingInlineNames, pendingInlineNameBytes)) {
  359. return false;
  360. }
  361. pendingBubbles.reserve(source.bubbles.size());
  362. pendingStates.reserve(source.states.size());
  363. pendingOccurrences.reserve(source.objects.size());
  364. std::size_t localState = 0;
  365. for (std::size_t ordinal = 0; ordinal < source.bubbles.size(); ++ordinal) {
  366. const catalog::Bubble& input = source.bubbles[ordinal];
  367. if (input.index != ordinal || input.firstState != localState
  368. || localState > source.states.size()
  369. || input.stateCount > source.states.size() - localState) {
  370. return false;
  371. }
  372. Bubble bubble{};
  373. bubble.scenarioIndex = static_cast<std::uint32_t>(output.nextScenario);
  374. bubble.bubbleOrdinal = static_cast<std::uint32_t>(ordinal);
  375. bubble.nameHash = input.nameHash;
  376. bubble.firstState = input.stateCount == 0
  377. ? 0
  378. : static_cast<std::uint32_t>(firstState + pendingStates.size());
  379. bubble.stateCount = input.stateCount;
  380. if (!format_text(bubble.id,
  381. "bubble/%08x/%04x/%08x",
  382. static_cast<unsigned>(source.scenarioTag),
  383. static_cast<unsigned>(ordinal),
  384. static_cast<unsigned>(input.nameHash))) {
  385. return false;
  386. }
  387. const std::uint32_t bubbleIndex =
  388. static_cast<std::uint32_t>(firstBubble + pendingBubbles.size());
  389. pendingBubbles.push_back(bubble);
  390. for (std::uint32_t stateOrdinal = 0; stateOrdinal < input.stateCount; ++stateOrdinal) {
  391. if (!append_state(source.states[localState + stateOrdinal],
  392. source.scenarioTag,
  393. bubble.scenarioIndex,
  394. bubbleIndex,
  395. bubble.bubbleOrdinal,
  396. stateOrdinal,
  397. pendingStates)) {
  398. return false;
  399. }
  400. }
  401. localState += input.stateCount;
  402. }
  403. if (localState != source.states.size()) {
  404. return false;
  405. }
  406. std::size_t nextSlot = 0;
  407. std::size_t nextDescriptor = 0;
  408. bool havePreviousOccurrence = false;
  409. std::tuple<std::uint32_t, std::uint32_t, std::uint32_t> previousGroup{};
  410. std::uint32_t previousOrdinal{};
  411. for (std::size_t objectRow = 0; objectRow < source.objects.size(); ++objectRow) {
  412. const catalog::Object& input = source.objects[objectRow];
  413. if (input.bubbleRow >= source.bubbles.size() || input.stateRow >= source.states.size()
  414. || source.states[input.stateRow].bubbleRow != input.bubbleRow
  415. || input.registryTag != source.states[input.stateRow].registryTag
  416. || !valid_registry_field(input.registryDescriptor)
  417. || input.objectIndex == catalog::kNoRow) {
  418. return false;
  419. }
  420. const auto group = std::tuple(input.bubbleRow,
  421. input.stateRow,
  422. static_cast<std::uint32_t>(input.registryDescriptor));
  423. if (!havePreviousOccurrence || group != previousGroup) {
  424. if ((havePreviousOccurrence && !(previousGroup < group))
  425. || input.objectIndex != 0) {
  426. return false;
  427. }
  428. } else if (previousOrdinal == (std::numeric_limits<std::uint32_t>::max)()
  429. || input.objectIndex != previousOrdinal + 1U) {
  430. return false;
  431. }
  432. previousGroup = group;
  433. previousOrdinal = input.objectIndex;
  434. havePreviousOccurrence = true;
  435. Object definition{};
  436. if (!build_object(source,
  437. static_cast<std::uint32_t>(objectRow),
  438. nextSlot,
  439. nextDescriptor,
  440. definition)
  441. || !merge_object(std::move(definition), pendingObjects)) {
  442. return false;
  443. }
  444. const std::uint32_t bubbleIndex =
  445. static_cast<std::uint32_t>(firstBubble + input.bubbleRow);
  446. const std::uint32_t stateIndex =
  447. static_cast<std::uint32_t>(firstState + input.stateRow);
  448. Occurrence occurrence{};
  449. if (!build_occurrence(input,
  450. pendingStates[input.stateRow],
  451. source.scenarioTag,
  452. static_cast<std::uint32_t>(output.nextScenario),
  453. bubbleIndex,
  454. stateIndex,
  455. occurrence)) {
  456. return false;
  457. }
  458. pendingOccurrences.push_back(occurrence);
  459. }
  460. if (nextSlot != source.slots.size() || nextDescriptor != source.descriptors.size()) {
  461. return false;
  462. }
  463. std::vector<ObjectUpdate> objectUpdates{};
  464. std::vector<Object> newObjects{};
  465. objectUpdates.reserve(pendingObjects.size());
  466. newObjects.reserve(pendingObjects.size());
  467. for (Object& definition : pendingObjects) {
  468. const auto found = output.accumulator.objectRows.find(definition.objectTag);
  469. if (found == output.accumulator.objectRows.end()) {
  470. newObjects.push_back(std::move(definition));
  471. continue;
  472. }
  473. if (found->second >= output.objects.size()
  474. || output.objects[found->second].objectTag != definition.objectTag) {
  475. return false;
  476. }
  477. Object merged = output.objects[found->second];
  478. if (!merge_object(std::move(definition), merged)) {
  479. return false;
  480. }
  481. objectUpdates.push_back({found->second, std::move(merged)});
  482. }
  483. output.bubbles.reserve(firstBubble + pendingBubbles.size());
  484. output.states.reserve(firstState + pendingStates.size());
  485. output.occurrences.reserve(firstOccurrence + pendingOccurrences.size());
  486. output.objects.reserve(output.objects.size() + newObjects.size());
  487. output.accumulator.objectRows.reserve(output.objects.size() + newObjects.size());
  488. output.accumulator.inlineNames.reserve(output.accumulator.inlineNames.size()
  489. + pendingInlineNames.size());
  490. std::size_t insertedInlineNames = 0;
  491. std::size_t insertedObjectRows = 0;
  492. const auto roll_back_indexes = [&]() noexcept {
  493. for (std::size_t index = 0; index < insertedObjectRows; ++index) {
  494. output.accumulator.objectRows.erase(newObjects[index].objectTag);
  495. }
  496. for (std::size_t index = 0; index < insertedInlineNames; ++index) {
  497. output.accumulator.inlineNames.erase(pendingInlineNames[index]);
  498. }
  499. };
  500. try {
  501. for (const std::string& value : pendingInlineNames) {
  502. if (!output.accumulator.inlineNames.insert(value).second) {
  503. roll_back_indexes();
  504. return false;
  505. }
  506. ++insertedInlineNames;
  507. }
  508. for (std::size_t index = 0; index < newObjects.size(); ++index) {
  509. const std::size_t row = output.objects.size() + index;
  510. if (!output.accumulator.objectRows.emplace(newObjects[index].objectTag, row)
  511. .second) {
  512. roll_back_indexes();
  513. return false;
  514. }
  515. ++insertedObjectRows;
  516. }
  517. } catch (...) {
  518. roll_back_indexes();
  519. return false;
  520. }
  521. for (ObjectUpdate& update : objectUpdates) {
  522. output.objects[update.row] = std::move(update.value);
  523. }
  524. for (Object& object : newObjects) {
  525. output.objects.push_back(std::move(object));
  526. }
  527. output.accumulator.inlineNameBytes += pendingInlineNameBytes;
  528. output.bubbles.insert(output.bubbles.end(), pendingBubbles.begin(), pendingBubbles.end());
  529. output.states.insert(output.states.end(), pendingStates.begin(), pendingStates.end());
  530. output.occurrences.insert(
  531. output.occurrences.end(), pendingOccurrences.begin(), pendingOccurrences.end());
  532. Scenario& committed = output.scenarios[output.nextScenario];
  533. committed.firstBubble =
  534. pendingBubbles.empty() ? 0 : static_cast<std::uint32_t>(firstBubble);
  535. committed.bubbleCount = static_cast<std::uint32_t>(pendingBubbles.size());
  536. committed.firstState = pendingStates.empty() ? 0 : static_cast<std::uint32_t>(firstState);
  537. committed.stateCount = static_cast<std::uint32_t>(pendingStates.size());
  538. committed.firstOccurrence =
  539. pendingOccurrences.empty() ? 0 : static_cast<std::uint32_t>(firstOccurrence);
  540. committed.occurrenceCount = static_cast<std::uint32_t>(pendingOccurrences.size());
  541. ++output.nextScenario;
  542. return true;
  543. } catch (...) {
  544. return false;
  545. }
  546. }
  547. } // namespace sunrise::client::content::activity::sdk_generation::topology_inventory