protoc-gen-gogo always appends a '_' to the field in the message


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


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

Answered By – tomaspavlic

Answer Checked By – Dawn Plyler (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.