We're using go-amino in cosmos. We have pointers to boolean values in our message structs in order to be able to differentiate whether a field was omitted or set to false.
However, when a pointer to false is marshalled then unmarshalled (binary only, the JSON methods work), the resulting value is nil.
Test program
Source
package main
import (
"fmt"
"github.com/tendermint/go-amino"
)
func main() {
var cdc = amino.NewCodec()
type SimpleStruct struct {
BoolPtrTrue *bool
BoolPtrFalse *bool
}
t := true
f := false
s := SimpleStruct{
BoolPtrTrue: &t,
BoolPtrFalse: &f,
}
b, _ := cdc.MarshalBinaryBare(s)
var s2 SimpleStruct
cdc.UnmarshalBinaryBare(b, &s2)
fmt.Println(s2.BoolPtrTrue)
fmt.Println(*s2.BoolPtrTrue)
fmt.Println(s2.BoolPtrFalse)
fmt.Println(*s2.BoolPtrFalse)
}
Description
We're using go-amino in cosmos. We have pointers to boolean values in our message structs in order to be able to differentiate whether a field was omitted or set to
false
.However, when a pointer to
false
is marshalled then unmarshalled (binary only, the JSON methods work), the resulting value isnil
.Test program
Source
Output
Playground link
https://play.golang.org/p/x05ph3bq2zd
Thank you!