(item)
| 574 | * @param {ComplexSerializableType} item item to serialize |
| 575 | */ |
| 576 | const process = (item) => { |
| 577 | if (Buffer.isBuffer(item)) { |
| 578 | // check if we can emit a reference |
| 579 | const ref = referenceable.get(item); |
| 580 | if (ref !== undefined) { |
| 581 | result.push(ESCAPE, ref - currentPos); |
| 582 | return; |
| 583 | } |
| 584 | const alreadyUsedBuffer = dedupeBuffer(item); |
| 585 | if (alreadyUsedBuffer !== item) { |
| 586 | const ref = referenceable.get(alreadyUsedBuffer); |
| 587 | if (ref !== undefined) { |
| 588 | referenceable.set(item, ref); |
| 589 | result.push(ESCAPE, ref - currentPos); |
| 590 | return; |
| 591 | } |
| 592 | item = alreadyUsedBuffer; |
| 593 | } |
| 594 | addReferenceable(item); |
| 595 | |
| 596 | result.push(/** @type {Buffer} */ (item)); |
| 597 | } else if (item === ESCAPE) { |
| 598 | result.push(ESCAPE, ESCAPE_ESCAPE_VALUE); |
| 599 | } else if ( |
| 600 | typeof item === "object" |
| 601 | // We don't have to check for null as ESCAPE is null and this has been checked before |
| 602 | ) { |
| 603 | // check if we can emit a reference |
| 604 | const ref = referenceable.get(item); |
| 605 | if (ref !== undefined) { |
| 606 | result.push(ESCAPE, ref - currentPos); |
| 607 | return; |
| 608 | } |
| 609 | |
| 610 | if (cycleStack.has(item)) { |
| 611 | throw new Error( |
| 612 | "This is a circular references. To serialize circular references use 'setCircularReference' somewhere in the circle during serialize and deserialize." |
| 613 | ); |
| 614 | } |
| 615 | |
| 616 | const { request, name, serializer } = ObjectMiddleware.getSerializerFor( |
| 617 | /** @type {Constructor} */ |
| 618 | (item) |
| 619 | ); |
| 620 | const key = `${request}/${name}`; |
| 621 | const lastIndex = objectTypeLookup.get(key); |
| 622 | |
| 623 | if (lastIndex === undefined) { |
| 624 | objectTypeLookup.set(key, currentPosTypeLookup++); |
| 625 | |
| 626 | result.push(ESCAPE, request, name); |
| 627 | } else { |
| 628 | result.push(ESCAPE, currentPosTypeLookup - lastIndex); |
| 629 | } |
| 630 | |
| 631 | cycleStack.add(item); |
| 632 | |
| 633 | try { |
nothing calls this directly
no test coverage detected