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

Method read

javascript/packages/core/lib/gen/map.ts:299–339  ·  view source on GitHub ↗
(fromRef: boolean)

Source from the content-addressed store, hash-verified

297 }
298
299 read(fromRef: boolean): any {
300 let count = this.readContext.reader.readVarUint32Small7();
301 const result = new Map();
302 if (fromRef) {
303 this.readContext.reference(result);
304 }
305 while (count > 0) {
306 const header = this.readContext.reader.readUint8();
307 const valueHeader = (header >> 3) & 0b111;
308 const keyHeader = header & 0b111;
309 let chunkSize = 0;
310 if (valueHeader & MapFlags.HAS_NULL || keyHeader & MapFlags.HAS_NULL) {
311 chunkSize = 1;
312 } else {
313 chunkSize = this.readContext.reader.readUint8();
314 }
315 let keySerializer = this.keySerializer;
316 let valueSerializer = this.valueSerializer;
317
318 if (
319 !(keyHeader & MapFlags.HAS_NULL)
320 && !(valueHeader & MapFlags.HAS_NULL)
321 ) {
322 if (!(keyHeader & MapFlags.DECL_ELEMENT_TYPE)) {
323 keySerializer = AnyHelper.detectSerializer(this.readContext);
324 }
325
326 if (!(valueHeader & MapFlags.DECL_ELEMENT_TYPE)) {
327 valueSerializer = AnyHelper.detectSerializer(this.readContext);
328 }
329 }
330
331 for (let index = 0; index < chunkSize; index++) {
332 const key = this.readElement(keyHeader, keySerializer);
333 const value = this.readElement(valueHeader, valueSerializer);
334 result.set(key, value);
335 count--;
336 }
337 }
338 return result;
339 }
340}
341
342export class MapSerializerGenerator extends BaseSerializerGenerator {

Callers

nothing calls this directly

Calls 6

readElementMethod · 0.95
detectSerializerMethod · 0.80
referenceMethod · 0.65
readVarUint32Small7Method · 0.45
readUint8Method · 0.45
setMethod · 0.45

Tested by

no test coverage detected