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

Function setMapValue

go/fory/map.go:690–709  ·  view source on GitHub ↗

setMapValue sets a key-value pair into a map, handling interface types

(mapVal, key, value reflect.Value)

Source from the content-addressed store, hash-verified

688
689// setMapValue sets a key-value pair into a map, handling interface types
690func setMapValue(mapVal, key, value reflect.Value) {
691 mapKeyType := mapVal.Type().Key()
692 mapValueType := mapVal.Type().Elem()
693
694 finalKey := key
695 if mapKeyType.Kind() == reflect.Interface && !key.Type().AssignableTo(mapKeyType) {
696 ptr := reflect.New(key.Type())
697 ptr.Elem().Set(key)
698 finalKey = ptr
699 }
700
701 finalValue := value
702 if mapValueType.Kind() == reflect.Interface && !value.Type().AssignableTo(mapValueType) {
703 ptr := reflect.New(value.Type())
704 ptr.Elem().Set(value)
705 finalValue = ptr
706 }
707
708 mapVal.SetMapIndex(finalKey, finalValue)
709}

Callers 1

readChunkMethod · 0.85

Calls 3

KindMethod · 0.80
TypeMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected