(accessor: string)
| 716 | } |
| 717 | |
| 718 | write(accessor: string): string { |
| 719 | if (!this.typeInfo.options?.props || Object.keys(this.typeInfo.options.props).length === 0) { |
| 720 | const hash = this.typeMeta.computeStructHash(); |
| 721 | return `${!this.builder.resolver.isCompatible() ? this.builder.writer.writeInt32(hash) : ""}`; |
| 722 | } |
| 723 | const hash = this.typeMeta.computeStructHash(); |
| 724 | const fieldWrites: string[] = []; |
| 725 | for (let i = 0; i < this.sortedProps.length;) { |
| 726 | const current = this.sortedProps[i]; |
| 727 | if (isDirectVarInt32Field(current.typeInfo, this.builder.resolver)) { |
| 728 | let end = i + 1; |
| 729 | while ( |
| 730 | end < this.sortedProps.length |
| 731 | && isDirectVarInt32Field(this.sortedProps[end].typeInfo, this.builder.resolver) |
| 732 | ) { |
| 733 | end++; |
| 734 | } |
| 735 | if (end - i > 1) { |
| 736 | fieldWrites.push(this.writeVarInt32Run(accessor, this.sortedProps.slice(i, end))); |
| 737 | i = end; |
| 738 | continue; |
| 739 | } |
| 740 | } |
| 741 | const InnerGeneratorClass = CodegenRegistry.get(current.typeInfo.typeId); |
| 742 | if (!InnerGeneratorClass) { |
| 743 | throw new Error(`${current.typeInfo.typeId} generator not exists`); |
| 744 | } |
| 745 | const innerGenerator = new InnerGeneratorClass(current.typeInfo, this.builder, this.scope); |
| 746 | const fieldAccessor = `${accessor}${CodecBuilder.safePropAccessor(current.key)}`; |
| 747 | fieldWrites.push(this.writeField(current.key, current.typeInfo, fieldAccessor, innerGenerator.writeEmbed())); |
| 748 | i++; |
| 749 | } |
| 750 | return ` |
| 751 | ${!this.builder.resolver.isCompatible() ? this.builder.writer.writeInt32(hash) : ""} |
| 752 | ${fieldWrites.join(";\n")} |
| 753 | `; |
| 754 | } |
| 755 | |
| 756 | private writeVarInt32Run( |
| 757 | accessor: string, |
nothing calls this directly
no test coverage detected