MCPcopy Create free account
hub / github.com/couchbase/fleece / _applyArray

Method _applyArray

Fleece/Core/JSONDelta.cc:284–329  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

282
283
284 inline void JSONDelta::_applyArray(const Value *old, const Array* NONNULL delta) {
285 switch (delta->count()) {
286 case 0:
287 // Deletion:
288 throwIf(!old, InvalidData, "Invalid deletion in delta");
289 // 'undefined' in the context of a dict value means a deletion of a key
290 // inherited from the parent.
291 _decoder->writeValue(Value::kUndefinedValue);
292 break;
293 case 1:
294 // Insertion / replacement:
295 _decoder->writeValue(delta->get(0));
296 break;
297 case 2:
298 // Replacement (JsonDiffPatch format):
299 throwIf(!old, InvalidData, "Invalid replace in delta");
300 _decoder->writeValue(delta->get(1));
301 break;
302 case 3: {
303 switch(delta->get(2)->asInt()) {
304 case kDeletionCode:
305 // JsonDiffPatch deletion:
306 throwIf(!old, InvalidData, "Invalid deletion in delta");
307 _decoder->writeValue(Value::kUndefinedValue);
308 break;
309 case kTextDiffCode: {
310 // Text diff:
311 slice oldStr;
312 if (old)
313 oldStr = old->asString();
314 throwIf(!oldStr, InvalidData, "Invalid text replace in delta");
315 slice diff = delta->get(0)->asString();
316 throwIf(diff.size == 0, InvalidData, "Invalid text diff in delta");
317 auto nuuStr = applyStringDelta(oldStr, diff);
318 _decoder->writeString(nuuStr);
319 break;
320 }
321 default:
322 FleeceException::_throw(InvalidData, "Unknown mode in delta");
323 }
324 break;
325 }
326 default:
327 FleeceException::_throw(InvalidData, "Bad array count in delta");
328 }
329 }
330
331
332 inline void JSONDelta::_patchDict(const Dict* NONNULL old, const Dict* NONNULL delta) {

Callers

nothing calls this directly

Calls 6

countMethod · 0.45
writeValueMethod · 0.45
getMethod · 0.45
asIntMethod · 0.45
asStringMethod · 0.45
writeStringMethod · 0.45

Tested by

no test coverage detected