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)
| 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. |
| 506 | func 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 | |
| 522 | func (s setSerializer) Read(ctx *ReadContext, refMode RefMode, readType bool, hasGenerics bool, value reflect.Value) { |
| 523 | buf := ctx.Buffer() |
no test coverage detected