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

Function writeRefOrNull

javascript/packages/core/lib/gen/serializer.ts:132–158  ·  view source on GitHub ↗
(accessor: string, assignStmt: (expr: string) => string)

Source from the content-addressed store, hash-verified

130 }
131
132 writeRefOrNull(accessor: string, assignStmt: (expr: string) => string) {
133 let refFlagStmt = "";
134 if (this.needToWriteRef()) {
135 const existsId = this.scope.uniqueName("existsId");
136 refFlagStmt = `
137 const ${existsId} = ${this.builder.referenceResolver.getWrittenRefId(accessor)};
138 if (typeof ${existsId} === "number") {
139 ${this.builder.writer.writeInt8(RefFlags.RefFlag)}
140 ${this.builder.writer.writeVarUInt32(existsId)}
141 ${assignStmt("true")};
142 } else {
143 ${this.builder.writer.writeInt8(RefFlags.RefValueFlag)}
144 ${this.builder.referenceResolver.writeRef(accessor)}
145 }
146 `;
147 } else {
148 refFlagStmt = this.builder.writer.writeInt8(RefFlags.NotNullValueFlag);
149 }
150 return `
151 if (${accessor} === null || ${accessor} === undefined) {
152 ${this.builder.writer.writeInt8(RefFlags.NullFlag)};
153 ${assignStmt("true")};
154 } else {
155 ${refFlagStmt}
156 }
157 `;
158 }
159
160 writeTypeInfo(accessor: string) {
161 void accessor;

Callers

nothing calls this directly

Calls 6

uniqueNameMethod · 0.80
needToWriteRefMethod · 0.65
writeRefMethod · 0.65
getWrittenRefIdMethod · 0.45
writeInt8Method · 0.45
writeVarUInt32Method · 0.45

Tested by

no test coverage detected