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

Method constructor

javascript/packages/core/lib/gen/union.ts:36–60  ·  view source on GitHub ↗
(typeInfo: TypeInfo, builder: CodecBuilder, scope: Scope)

Source from the content-addressed store, hash-verified

34 caseGenerators = new Map<string, SerializerGenerator>();
35
36 constructor(typeInfo: TypeInfo, builder: CodecBuilder, scope: Scope) {
37 super(typeInfo, builder, scope);
38 this.typeInfo = typeInfo;
39 this.detectedSerializer = this.scope.declareVar("detectedSerializer", "null");
40 this.writerSerializer = this.scope.declareVar("writerSerializer", "null");
41
42 // Build case-to-type mapping from typeInfo.options.cases
43 const cases = typeInfo.options?.cases;
44 if (cases) {
45 const caseEntries: string[] = [];
46 for (const [caseIdx, caseTypeInfo] of Object.entries(cases)) {
47 const ti = caseTypeInfo as TypeInfo;
48 const isNamed = TypeId.isNamedType(ti._typeId);
49 const named = isNamed ? `"${ti.named}"` : "null";
50 caseEntries.push(`${caseIdx}: { typeId: ${ti.typeId}, userTypeId: ${ti.userTypeId ?? -1}, named: ${named} }`);
51 this.caseGenerators.set(
52 caseIdx,
53 CodegenRegistry.newGeneratorByTypeInfo(ti, this.builder, this.scope),
54 );
55 }
56 this.caseTypesVar = this.scope.declareVar("caseTypes", `{ ${caseEntries.join(", ")} }`);
57 } else {
58 this.caseTypesVar = this.scope.declareVar("caseTypes", "null");
59 }
60 }
61
62 needToWriteRef(): boolean {
63 return false;

Callers

nothing calls this directly

Calls 4

declareVarMethod · 0.80
isNamedTypeMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected