| 372 | |
| 373 | |
| 374 | inline void JSONDelta::_patchArray(const Array* NONNULL old, const Dict* NONNULL delta) { |
| 375 | // Array: Incremental update |
| 376 | _decoder->beginArray(); |
| 377 | uint32_t index = 0; |
| 378 | const Value *remainder = nullptr; |
| 379 | for (Array::iterator iOld(old); iOld; ++iOld, ++index) { |
| 380 | auto oldItem = iOld.value(); |
| 381 | char key[10]; |
| 382 | sprintf(key, "%d", index); |
| 383 | auto replacement = delta->get(slice(key)); |
| 384 | if (replacement) { |
| 385 | // Patch this array item: |
| 386 | _apply(oldItem, replacement); |
| 387 | } else { |
| 388 | strcat(key, "-"); |
| 389 | remainder = delta->get(slice(key)); |
| 390 | if (remainder) { |
| 391 | break; |
| 392 | } else { |
| 393 | // Array item is unaffected: |
| 394 | _decoder->writeValue(oldItem); |
| 395 | } |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | if (!remainder) { |
| 400 | char key[10]; |
| 401 | sprintf(key, "%d-", old->count()); |
| 402 | remainder = delta->get(slice(key)); |
| 403 | } |
| 404 | if (remainder) { |
| 405 | // Remainder of array is replaced by the array from the delta: |
| 406 | auto remainderArray = remainder->asArray(); |
| 407 | throwIf(!remainderArray, InvalidData, "Invalid array remainder in delta"); |
| 408 | for (Array::iterator iRem(remainderArray); iRem; ++iRem) |
| 409 | _decoder->writeValue(iRem.value()); |
| 410 | } |
| 411 | _decoder->endArray(); |
| 412 | } |
| 413 | |
| 414 | |
| 415 | // Does this delta represent a deletion? |
nothing calls this directly
no test coverage detected