MCPcopy Create free account
hub / github.com/apache/fory / write

Method write

javascript/packages/core/lib/gen/struct.ts:718–754  ·  view source on GitHub ↗
(accessor: string)

Source from the content-addressed store, hash-verified

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,

Callers

nothing calls this directly

Calls 11

writeVarInt32RunMethod · 0.95
writeFieldMethod · 0.95
isDirectVarInt32FieldFunction · 0.85
safePropAccessorMethod · 0.80
getMethod · 0.65
writeEmbedMethod · 0.65
keysMethod · 0.45
computeStructHashMethod · 0.45
isCompatibleMethod · 0.45
writeInt32Method · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected