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

Function readMapInt32Int32

go/fory/map_primitive.go:600–643  ·  view source on GitHub ↗

readMapInt32Int32 reads map[int32]int32 using chunk protocol

(ctx *ReadContext)

Source from the content-addressed store, hash-verified

598
599// readMapInt32Int32 reads map[int32]int32 using chunk protocol
600func readMapInt32Int32(ctx *ReadContext) map[int32]int32 {
601 err := ctx.Err()
602 buf := ctx.Buffer()
603 size, ok := readTypedMapSize(ctx)
604 result := make(map[int32]int32)
605 if !ok {
606 return result
607 }
608 result = make(map[int32]int32, size)
609
610 for size > 0 {
611 chunkHeader := buf.ReadUint8(err)
612 if chunkHeader&(TRACKING_KEY_REF|KEY_HAS_NULL|TRACKING_VALUE_REF|VALUE_HAS_NULL) != 0 {
613 ctx.SetError(DeserializationError("typed map reader does not support ref/null chunks"))
614 return result
615 }
616
617 chunkSize := int(buf.ReadUint8(err))
618 if ctx.HasError() {
619 return result
620 }
621 if chunkSize == 0 || chunkSize > size {
622 ctx.SetError(DeserializationErrorf("invalid map chunk size %d for remaining length %d", chunkSize, size))
623 return result
624 }
625 if (chunkHeader & KEY_DECL_TYPE) == 0 {
626 if !ctx.readExpectedTypeID(VARINT32) {
627 return result
628 }
629 }
630 if (chunkHeader & VALUE_DECL_TYPE) == 0 {
631 if !ctx.readExpectedTypeID(VARINT32) {
632 return result
633 }
634 }
635 for i := 0; i < chunkSize; i++ {
636 k := buf.ReadVarint32(err)
637 v := buf.ReadVarint32(err)
638 result[k] = v
639 size--
640 }
641 }
642 return result
643}
644
645// writeMapInt64Int64 writes map[int64]int64 using chunk protocol
646// When hasGenerics=true, element types are known so we set DECL_TYPE flags and skip type info

Callers 2

ReadInt32Int32MapMethod · 0.85
ReadDataMethod · 0.85

Calls 10

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

Tested by

no test coverage detected