Compare commits
3 Commits
f10327356e
...
5c2b8a0582
| Author | SHA1 | Date | |
|---|---|---|---|
| 5c2b8a0582 | |||
| 4575fa229b | |||
| cbfb513933 |
@ -24,7 +24,7 @@ const preamble = `
|
||||
|
||||
const static = `
|
||||
// Table is a KTV table with an undefined schema.
|
||||
type Table map[uint16] any
|
||||
type Table = map[uint16] any
|
||||
|
||||
// Message is any message that can be sent along this protocol.
|
||||
type Message interface {
|
||||
|
||||
@ -242,12 +242,22 @@ func decodeAnyOrError(decoder *Decoder, destination reflect.Value, tag Tag) (n i
|
||||
}
|
||||
lengthCast, err := Uint64ToIntSafe(length)
|
||||
if err != nil { return n, err }
|
||||
if isTypeAny(destination.Type()) {
|
||||
// need a skeleton value if we are assigning to any.
|
||||
value := reflect.MakeMapWithSize(reflect.TypeOf(dummyMap), lengthCast)
|
||||
destination.Set(value)
|
||||
destination = value
|
||||
}
|
||||
|
||||
// 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)
|
||||
destination.Set(value)
|
||||
destination = value
|
||||
|
||||
destination.Clear()
|
||||
for _ = range lengthCast {
|
||||
key, nn, err := decoder.ReadUint16()
|
||||
@ -387,7 +397,11 @@ func canSet(destination reflect.Type, tag Tag) error {
|
||||
return errCantAssignf("cannot assign array to %v", destination)
|
||||
}
|
||||
case KTV:
|
||||
if destination != reflect.TypeOf(dummyMap) {
|
||||
cantAssign :=
|
||||
destination.Kind() != reflect.Map ||
|
||||
destination.Key().Kind() != reflect.Uint16 ||
|
||||
!isTypeAny(destination.Elem())
|
||||
if cantAssign {
|
||||
return errCantAssignf("cannot assign table to %v", destination)
|
||||
}
|
||||
default:
|
||||
@ -497,9 +511,6 @@ func skeletonPointer(decoder *Decoder, tag Tag) (reflect.Value, error) {
|
||||
typ, err := typeOf(decoder, tag)
|
||||
if err != nil { return reflect.Value { }, err }
|
||||
value := reflect.New(typ)
|
||||
if tag.Is(KTV) {
|
||||
value.Elem().Set(reflect.MakeMap(typ))
|
||||
}
|
||||
return value, nil
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user