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

Function readMapStringInt

go/fory/map_primitive.go:341–384  ·  view source on GitHub ↗

readMapStringInt reads map[string]int using chunk protocol

(ctx *ReadContext)

Source from the content-addressed store, hash-verified

339
340// readMapStringInt reads map[string]int using chunk protocol
341func readMapStringInt(ctx *ReadContext) map[string]int {
342 err := ctx.Err()
343 buf := ctx.Buffer()
344 size, ok := readTypedMapSize(ctx)
345 result := make(map[string]int)
346 if !ok {
347 return result
348 }
349 result = make(map[string]int, size)
350
351 for size > 0 {
352 chunkHeader := buf.ReadUint8(err)
353 if chunkHeader&(TRACKING_KEY_REF|KEY_HAS_NULL|TRACKING_VALUE_REF|VALUE_HAS_NULL) != 0 {
354 ctx.SetError(DeserializationError("typed map reader does not support ref/null chunks"))
355 return result
356 }
357
358 chunkSize := int(buf.ReadUint8(err))
359 if ctx.HasError() {
360 return result
361 }
362 if chunkSize == 0 || chunkSize > size {
363 ctx.SetError(DeserializationErrorf("invalid map chunk size %d for remaining length %d", chunkSize, size))
364 return result
365 }
366 if (chunkHeader & KEY_DECL_TYPE) == 0 {
367 if !ctx.readExpectedTypeID(STRING) {
368 return result
369 }
370 }
371 if (chunkHeader & VALUE_DECL_TYPE) == 0 {
372 if !ctx.readExpectedTypeID(VARINT64) {
373 return result
374 }
375 }
376 for i := 0; i < chunkSize; i++ {
377 k := readString(buf, err)
378 v := buf.ReadVarint64(err)
379 result[k] = int(v)
380 size--
381 }
382 }
383 return result
384}
385
386// writeMapStringFloat64 writes map[string]float64 using chunk protocol
387// When hasGenerics=true, element types are known so we set DECL_TYPE flags and skip type info

Callers 2

ReadStringIntMapMethod · 0.85
ReadDataMethod · 0.85

Calls 11

readTypedMapSizeFunction · 0.85
DeserializationErrorFunction · 0.85
DeserializationErrorfFunction · 0.85
readStringFunction · 0.85
ReadUint8Method · 0.80
readExpectedTypeIDMethod · 0.80
ErrMethod · 0.45
BufferMethod · 0.45
SetErrorMethod · 0.45
HasErrorMethod · 0.45
ReadVarint64Method · 0.45

Tested by

no test coverage detected