On Wed, Aug 3, 2016 at 8:58 AM, Sankar <sankar.curios...@gmail.com> wrote: > > I have a .proto2 file, like: > > message s { > optional double a = 1; > } > > When I run protoc and generate the .pb.go file, it contains code like: > > type S struct { > A *float64 `protobuf:"fixed64,1,opt,name=a" > json:"a,omitempty"` > XXX_unrecognized []byte `json:"-"` > } > > Why is the A field here a pointer instead of a normal float64 ?
Because proto2 records not only the value of each field, but also whether the field is present or not. Using a pointer is how the Go implementations indicates whether the field is present. This is better in proto3. If you can switch to proto3, do so. Ian -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.