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

Function resolveRootSerializer

integration_tests/idl_tests/javascript/roundtrip.ts:127–162  ·  view source on GitHub ↗
(fory: Fory, bytes: Uint8Array)

Source from the content-addressed store, hash-verified

125}
126
127function resolveRootSerializer(fory: Fory, bytes: Uint8Array): Serializer {
128 fory.readContext.reset(bytes);
129 const reader = fory.readContext.reader;
130 const bitmap = reader.readUint8();
131 const supportedBitmap =
132 ConfigFlags.isCrossLanguageFlag | ConfigFlags.isOutOfBandFlag;
133 if ((bitmap & ~supportedBitmap) !== 0) {
134 throw new Error("unsupported root header bitmap");
135 }
136 if (
137 (bitmap & ConfigFlags.isCrossLanguageFlag) !==
138 ConfigFlags.isCrossLanguageFlag
139 ) {
140 throw new Error("support crosslanguage mode only");
141 }
142 if ((bitmap & ConfigFlags.isOutOfBandFlag) === ConfigFlags.isOutOfBandFlag) {
143 throw new Error("outofband mode is not supported now");
144 }
145 const refFlag = fory.readContext.readRefFlag();
146 if (refFlag === RefFlags.NullFlag) {
147 throw new Error("IDL roundtrip does not support null root payloads");
148 }
149 if (refFlag === RefFlags.RefFlag) {
150 throw new Error("IDL roundtrip root payload must not be a back reference");
151 }
152 // Generated JS IDL outputs are plain interfaces, so generic serialize(value)
153 // cannot rediscover the root struct serializer. Reuse the runtime's existing
154 // serializer detection from the payload, then map back to the local
155 // registered serializer when available.
156 const detectedSerializer = AnyHelper.detectSerializer(fory.readContext);
157 const resolvedSerializer =
158 fory.typeResolver.getSerializerByTypeInfo(
159 detectedSerializer.getTypeInfo(),
160 ) ?? detectedSerializer;
161 return resolvedSerializer;
162}
163
164function runFileRoundTrip<T>(
165 envVar: string,

Callers 1

runFileRoundTripFunction · 0.85

Calls 6

detectSerializerMethod · 0.80
resetMethod · 0.65
readUint8Method · 0.45
readRefFlagMethod · 0.45
getTypeInfoMethod · 0.45

Tested by

no test coverage detected