tape: Correctly decode into a table destination all the time
This commit is contained in:
parent
4575fa229b
commit
5c2b8a0582
@ -242,12 +242,22 @@ func decodeAnyOrError(decoder *Decoder, destination reflect.Value, tag Tag) (n i
|
|||||||
}
|
}
|
||||||
lengthCast, err := Uint64ToIntSafe(length)
|
lengthCast, err := Uint64ToIntSafe(length)
|
||||||
if err != nil { return n, err }
|
if err != nil { return n, err }
|
||||||
if isTypeAny(destination.Type()) {
|
|
||||||
// need a skeleton value if we are assigning to any.
|
// im fucking so done dude. im so fucking done. this was
|
||||||
|
// supposed to only run when we need it but i guess it runs all
|
||||||
|
// the time, because when we get a map destination (a valid,
|
||||||
|
// allocated one) we break apart on SetMapIndex because of a nil
|
||||||
|
// map. yeah thats right. a fucking nil map panic. on the map we
|
||||||
|
// just allocated. but running this unconditionally (whether or
|
||||||
|
// not we receive an empty any value) actually makes it fucking
|
||||||
|
// work. go figure().
|
||||||
|
//
|
||||||
|
// (the map allocation functionality in skeletonPointer has been
|
||||||
|
// removed)
|
||||||
value := reflect.MakeMapWithSize(reflect.TypeOf(dummyMap), lengthCast)
|
value := reflect.MakeMapWithSize(reflect.TypeOf(dummyMap), lengthCast)
|
||||||
destination.Set(value)
|
destination.Set(value)
|
||||||
destination = value
|
destination = value
|
||||||
}
|
|
||||||
destination.Clear()
|
destination.Clear()
|
||||||
for _ = range lengthCast {
|
for _ = range lengthCast {
|
||||||
key, nn, err := decoder.ReadUint16()
|
key, nn, err := decoder.ReadUint16()
|
||||||
@ -355,12 +365,8 @@ func encodeAnyMap(encoder *Encoder, value any, tag Tag) (n int, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func canSet(destination reflect.Type, tag Tag) error {
|
func canSet(destination reflect.Type, tag Tag) error {
|
||||||
fmt.Println("== CAN SET ====================")
|
|
||||||
fmt.Println(destination)
|
|
||||||
fmt.Println(tag)
|
|
||||||
// anything can be assigned to `any`
|
// anything can be assigned to `any`
|
||||||
if isTypeAny(destination) {
|
if isTypeAny(destination) {
|
||||||
fmt.Println("OK")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
switch tag.WithoutCN() {
|
switch tag.WithoutCN() {
|
||||||
@ -401,7 +407,6 @@ func canSet(destination reflect.Type, tag Tag) error {
|
|||||||
default:
|
default:
|
||||||
return fmt.Errorf("unknown TN %d", tag.TN())
|
return fmt.Errorf("unknown TN %d", tag.TN())
|
||||||
}
|
}
|
||||||
fmt.Println("OK")
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -506,9 +511,6 @@ func skeletonPointer(decoder *Decoder, tag Tag) (reflect.Value, error) {
|
|||||||
typ, err := typeOf(decoder, tag)
|
typ, err := typeOf(decoder, tag)
|
||||||
if err != nil { return reflect.Value { }, err }
|
if err != nil { return reflect.Value { }, err }
|
||||||
value := reflect.New(typ)
|
value := reflect.New(typ)
|
||||||
if tag.Is(KTV) {
|
|
||||||
value.Elem().Set(reflect.MakeMap(typ))
|
|
||||||
}
|
|
||||||
return value, nil
|
return value, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user