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

Method read

javascript/packages/core/lib/gen/union.ts:185–206  ·  view source on GitHub ↗
(assignStmt: (v: string) => string, refState: string)

Source from the content-addressed store, hash-verified

183 }
184
185 read(assignStmt: (v: string) => string, refState: string): string {
186 void refState;
187 const caseIndex = this.scope.uniqueName("caseIndex");
188 const refFlag = this.scope.uniqueName("refFlag");
189 const unionValue = this.scope.uniqueName("unionValue");
190 const caseInfo = this.scope.uniqueName("caseInfo");
191 const result = this.scope.uniqueName("result");
192 return `
193 const ${caseIndex} = ${this.builder.reader.readVarUInt32()};
194 const ${refFlag} = ${this.builder.reader.readInt8()};
195 let ${unionValue} = null;
196 if (${refFlag} === ${RefFlags.NullFlag}) {
197 ${unionValue} = null;
198 } else if (${refFlag} === ${RefFlags.RefFlag}) {
199 ${unionValue} = ${this.builder.referenceResolver.getReadRef(this.builder.reader.readVarUInt32())};
200 } else {
201 ${this.readDeclaredCases(caseIndex, unionValue, refFlag, caseInfo)}
202 }
203 const ${result} = { case: ${caseIndex}, value: ${unionValue} };
204 ${assignStmt(result)}
205 `;
206 }
207
208 writeTypeInfo(): string {
209 const internalTypeId = this.typeInfo._typeId;

Callers

nothing calls this directly

Calls 5

readDeclaredCasesMethod · 0.95
uniqueNameMethod · 0.80
getReadRefMethod · 0.65
readVarUInt32Method · 0.45
readInt8Method · 0.45

Tested by

no test coverage detected