(fory: Fory, bytes: Uint8Array)
| 125 | } |
| 126 | |
| 127 | function 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 | |
| 164 | function runFileRoundTrip<T>( |
| 165 | envVar: string, |
no test coverage detected