Hi

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 ? Is there 
any way to get it a float64 ?

I ask this because, the code becomes too verbose. If it was just a float, I 
would have written code like:

var s pb.S
s.A, err = strconv.ParseFloat(strings.Replace(lines[0], ",", "", -1), 64)

whereas now I am forced to write:

f, err = strpconv.ParseFloat(strings.Replace(lines[0], ",", "", -1), 64)
if err != nil {
}
s.A = protobuf.Float64(f)


This is one extra line everywhere s.A is used. Also, in case of float64 it 
may be just one line. But if I have other structs as member elements in my 
structs, this code becomes even more complicated. Is there any way to 
generate code such that actual struct instances and datatype instances will 
be used instead of pointers ?

Thanks.

Sankar



-- 
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.

Reply via email to