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

Function toSerializer

javascript/packages/core/lib/gen/serializer.ts:283–359  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

281 }
282
283 toSerializer() {
284 this.scope.assertNameNotDuplicate("read");
285 this.scope.assertNameNotDuplicate("readInner");
286 this.scope.assertNameNotDuplicate("write");
287 this.scope.assertNameNotDuplicate("writeInner");
288 this.scope.assertNameNotDuplicate("typeResolver");
289 this.scope.assertNameNotDuplicate("external");
290 this.scope.assertNameNotDuplicate("options");
291 this.scope.assertNameNotDuplicate("typeInfo");
292
293 const declare = `
294 const getHash = () => {
295 return ${this.getHash()};
296 }
297 const getTypeMetaBytes = () => {
298 return ${this.getTypeMetaBytes()};
299 }
300 const write = (v) => {
301 ${this.write("v")}
302 };
303 const writeRef = (v) => {
304 ${this.writeRef("v")}
305 };
306 const writeNoRef = (v) => {
307 ${this.writeNoRef("v")}
308 };
309 const writeRefOrNull = (v) => {
310 ${this.writeRefOrNull("v", expr => `return ${expr};`)}
311 };
312 const writeTypeInfo = (v) => {
313 ${this.writeTypeInfo("v")}
314 };
315 const read = (fromRef) => {
316 ${this.read(assignStmt => `return ${assignStmt}`, "fromRef")}
317 };
318 const readRef = () => {
319 ${this.readRef(assignStmt => `return ${assignStmt}`)}
320 };
321 const readRefWithoutTypeInfo = () => {
322 ${this.readRefWithoutTypeInfo(assignStmt => `return ${assignStmt}`)}
323 };
324 const readNoRef = (fromRef) => {
325 ${this.readNoRef(assignStmt => `return ${assignStmt}`, "fromRef")}
326 };
327 const readTypeInfo = () => {
328 ${this.readTypeInfo()}
329 };
330 `;
331 return `
332 return function (typeResolver, external, typeInfo, options) {
333 ${this.scope.generate()}
334 ${declare}
335 return {
336 _initialized: true,
337 fixedSize: ${this.getFixedSize()},
338 needToWriteRef: () => ${this.needToWriteRef()},
339 getTypeId: () => ${this.getTypeId()},
340 getUserTypeId: () => ${this.getUserTypeId()},

Callers

nothing calls this directly

Calls 15

writeNoRefMethod · 0.80
getHashMethod · 0.65
getTypeMetaBytesMethod · 0.65
writeMethod · 0.65
writeRefMethod · 0.65
writeRefOrNullMethod · 0.65
writeTypeInfoMethod · 0.65
readMethod · 0.65
readRefMethod · 0.65
readNoRefMethod · 0.65

Tested by

no test coverage detected