tape: Fix KTV decoding not recognizing the any type

This commit is contained in:
Sasha Koshka 2025-06-27 14:02:38 -04:00
parent e16fec3a81
commit b174015319

View File

@ -69,7 +69,7 @@ func DecodeAny(decoder *Decoder, destination any, tag Tag) (n int, err error) {
func decodeAny(decoder *Decoder, destination reflect.Value, tag Tag) (n int, err error) { func decodeAny(decoder *Decoder, destination reflect.Value, tag Tag) (n int, err error) {
errWrongDestinationType := func(expected string) error { errWrongDestinationType := func(expected string) error {
return fmt.Errorf( return fmt.Errorf(
"expected %s destination, not %v", "expected &%s destination, not %v",
expected, destination) expected, destination)
} }
@ -138,14 +138,8 @@ func decodeAny(decoder *Decoder, destination reflect.Value, tag Tag) (n int, err
case KTV: case KTV:
// KTV: <length: UN> (<key: U16> <tag: Tag> <value>)* // KTV: <length: UN> (<key: U16> <tag: Tag> <value>)*
table := destination.Elem() table := destination.Elem()
if table.Kind() != reflect.Map { var dummyMap map[uint16] any
return n, errWrongDestinationType("map") if table.Type() != reflect.TypeOf(dummyMap) {
}
typ := table.Type()
if typ.Key().Kind() != reflect.Uint16 {
return n, errWrongDestinationType("map[uint16]")
}
if typ.Elem() != reflect.TypeOf(any(nil)) {
return n, errWrongDestinationType("map[uint16] any") return n, errWrongDestinationType("map[uint16] any")
} }
length, nn, err := decoder.ReadUintN(tag.CN() - 1) length, nn, err := decoder.ReadUintN(tag.CN() - 1)