Home > Software design >  protoc-gen-gogo always appends a '_' to the field in the message
protoc-gen-gogo always appends a '_' to the field in the message

Time:03-17

goTrying to generate golang pb.go file through protoc-gen-gogo. But it seems that there is a specific field 'uint64 sizeis always generated asSize_` with an unexpected _

The message is

message T {
    uint64 size = 1;
}

=>

The definition in the pb.go is

type T struct {
    Size_ ....
}

Thus my editor always pops an error like there no definition of Size_

My generated command is

protoc(v3) --gogo_out=. --gogo_opt=paths=source_relative *.proto

CodePudding user response:

Underscores may be appended to field names that might collide in anyway with generated names by protoc-gen-go. Size() method is one of the essentials method created by the generator to get the size of the protobuf message. The same applies for keywords reversed by target language (Golang in this instance).

  • Related