You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// right:int32 is ok
type T struct {
A int32
}
// wrong:int has no output,and no error
type T struct {
A int
}
func main() {
buf := new(bytes.Buffer)
t := T{1}
err := binary.Write(buf, binary.BigEndian, t)
if err != nil {
panic(err)
}
fmt.Println("buf.Bytes()=", buf.Bytes()) // if t.A is "int" but not "int32" type, here no out put.
}
The text was updated successfully, but these errors were encountered:
ianlancetaylor
changed the title
binary.Write() struct int type no output.
encoding/binary: Write() struct int type no output.
Nov 5, 2015
What version of Go are you on? Here (1.5.1), it does return an error: binary.Write: invalid type main.T. It's invalid because encoding/binary is for fixed size data, and int isn't fixed size: it can be 32 or 64 bits wide, depending on the architecture.
The text was updated successfully, but these errors were encountered: