I'm trying to shim an interface into something that knows how to properly serialize/deserialize that interface. Here is an example:
package foo
//go:generate go tool msgp -io=false -tests=false
//msgp:shim *Bar as:BarSerializer using:ToBarSerializer/unusedFn
//msgp:ignore BarSerializer Bar
type Bar interface{}
type Foo struct {
Bar
}
type BarSerializer struct {
Bar *Bar
}
func ToBarSerializer(b *Bar) BarSerializer {
return BarSerializer{Bar: b}
}
func (b BarSerializer) MarshalMsg(o []byte) ([]byte, error) {
// actual logic
return o, nil
}
func (b BarSerializer) UnmarshalMsg(o []byte) ([]byte, error) {
// actual logic
*b.Bar = nil // set appropriately
return o, nil
}
func (b BarSerializer) Msgsize() int {
return 0
}
Using this generation, the shim is completely unused. I believe it is because the .Alias call here does not set .Convert = true when IDENT types are provided in the as. As such, the shim logic isn't used at all in marshal/unmarshal/size.
Unconditionally setting Convert to true for aliases fixes this problem and properly uses the shim.
I'm trying to shim an interface into something that knows how to properly serialize/deserialize that interface. Here is an example:
Using this generation, the shim is completely unused. I believe it is because the
.Aliascall here does not set.Convert = truewhen IDENT types are provided in theas. As such, the shim logic isn't used at all in marshal/unmarshal/size.Unconditionally setting
Convertto true for aliases fixes this problem and properly uses the shim.