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

Method register

javascript/packages/core/lib/fory.ts:144–169  ·  view source on GitHub ↗
(constructor: any, customSerializer?: CustomSerializer<any>)

Source from the content-addressed store, hash-verified

142 deserialize(bytes: Uint8Array): InstanceType<T> | null;
143 };
144 register(constructor: any, customSerializer?: CustomSerializer<any>) {
145 let serializer: Serializer;
146 if (constructor.prototype?.[ForyTypeInfoSymbol]) {
147 const typeInfo: TypeInfo = (
148 constructor.prototype[ForyTypeInfoSymbol] as WithForyClsInfo
149 ).structTypeInfo;
150 typeInfo.freeze();
151 serializer = new Gen(this.typeResolver, {
152 creator: constructor,
153 customSerializer,
154 }).generateSerializer(typeInfo);
155 this.typeResolver.registerSerializer(typeInfo, serializer);
156 } else {
157 const typeInfo = constructor;
158 typeInfo.freeze();
159 serializer = new Gen(this.typeResolver, {
160 customSerializer,
161 }).generateSerializer(typeInfo);
162 this.typeResolver.registerSerializer(typeInfo, serializer);
163 }
164 return {
165 serializer,
166 serialize: this.getRootSerializer(serializer),
167 deserialize: this.getRootDeserializer(serializer),
168 };
169 }
170
171 deserialize<T = any>(
172 bytes: Uint8Array,

Callers 2

readCompatibleScalarFunction · 0.95
testTypeInfoFunction · 0.95

Calls 5

getRootSerializerMethod · 0.95
getRootDeserializerMethod · 0.95
freezeMethod · 0.80
generateSerializerMethod · 0.80
registerSerializerMethod · 0.65

Tested by 2

readCompatibleScalarFunction · 0.76
testTypeInfoFunction · 0.76