* Serializes this instance into the provided serializer context. * @param {ObjectSerializerContext} context context
({ write, writeSeparate })
| 618 | * @param {ObjectSerializerContext} context context |
| 619 | */ |
| 620 | serialize({ write, writeSeparate }) { |
| 621 | this._persistFreshContent(); |
| 622 | this._optimizeSmallContent(); |
| 623 | this._optimizeUnusedContent(); |
| 624 | this._gcOldestContent(); |
| 625 | for (const identifier of this.itemInfo.keys()) { |
| 626 | write(identifier); |
| 627 | } |
| 628 | write(null); // null as marker of the end of keys |
| 629 | for (const info of this.itemInfo.values()) { |
| 630 | write(info.etag); |
| 631 | } |
| 632 | for (const info of this.itemInfo.values()) { |
| 633 | write(info.lastAccess); |
| 634 | } |
| 635 | for (let i = 0; i < this.content.length; i++) { |
| 636 | const content = this.content[i]; |
| 637 | if (content !== undefined) { |
| 638 | write(content.items); |
| 639 | content.writeLazy((lazy) => |
| 640 | /** @type {NonNullable<ObjectSerializerContext["writeSeparate"]>} */ |
| 641 | (writeSeparate)(lazy, { name: `${i}` }) |
| 642 | ); |
| 643 | } else { |
| 644 | write(undefined); // undefined marks an empty content slot |
| 645 | } |
| 646 | } |
| 647 | write(null); // null as marker of the end of items |
| 648 | } |
| 649 | |
| 650 | /** |
| 651 | * Restores this instance from the provided deserializer context. |
no test coverage detected