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

Method write

javascript/packages/core/lib/gen/union.ts:136–151  ·  view source on GitHub ↗
(accessor: string)

Source from the content-addressed store, hash-verified

134 }
135
136 write(accessor: string): string {
137 const caseIndex = this.scope.uniqueName("caseIndex");
138 const unionValue = this.scope.uniqueName("unionValue");
139 const caseInfo = this.scope.uniqueName("caseInfo");
140 return `
141 const ${caseIndex} = ${accessor} && ${accessor}.case != null ? ${accessor}.case : 0;
142 ${this.builder.writer.writeVarUInt32(caseIndex)}
143 const ${unionValue} = ${accessor} && ${accessor}.value != null ? ${accessor}.value : null;
144 if (${unionValue} === null || ${unionValue} === undefined) {
145 ${this.builder.writer.writeInt8(RefFlags.NullFlag)}
146 } else {
147 const ${caseInfo} = ${this.caseTypesVar} ? ${this.caseTypesVar}[${caseIndex}] : null;
148 ${this.writeDeclaredCases(caseIndex, unionValue, caseInfo)}
149 }
150 `;
151 }
152
153 private readDynamicCaseValue(unionValue: string, refFlag: string) {
154 return `

Callers

nothing calls this directly

Calls 4

writeDeclaredCasesMethod · 0.95
uniqueNameMethod · 0.80
writeVarUInt32Method · 0.45
writeInt8Method · 0.45

Tested by

no test coverage detected