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

Function setMapKey

go/fory/set.go:506–520  ·  view source on GitHub ↗

setMapKey sets a key into a map (set), handling interface types where the concrete type may need to be wrapped in a pointer to implement the interface.

(mapValue, key reflect.Value, keyType reflect.Type)

Source from the content-addressed store, hash-verified

504// setMapKey sets a key into a map (set), handling interface types where
505// the concrete type may need to be wrapped in a pointer to implement the interface.
506func setMapKey(mapValue, key reflect.Value, keyType reflect.Type) {
507 if keyType.Kind() == reflect.Interface {
508 // Check if key is directly assignable to the interface
509 if key.Type().AssignableTo(keyType) {
510 mapValue.SetMapIndex(key, emptyStructVal)
511 } else {
512 // Try pointer - common case where interface has pointer receivers
513 ptr := reflect.New(key.Type())
514 ptr.Elem().Set(key)
515 mapValue.SetMapIndex(ptr, emptyStructVal)
516 }
517 } else {
518 mapValue.SetMapIndex(key, emptyStructVal)
519 }
520}
521
522func (s setSerializer) Read(ctx *ReadContext, refMode RefMode, readType bool, hasGenerics bool, value reflect.Value) {
523 buf := ctx.Buffer()

Callers 2

readSameTypeMethod · 0.85
readDifferentTypesMethod · 0.85

Calls 3

KindMethod · 0.80
TypeMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected