how to override protobuf enums value

Viewed 262

I use protoc to generate proto file to .go file . In Protocol Buffers, I want to use the enums value with self defined value.

  enum Region {
North_America = 0; // I want to set it to be "North America" use space replace the _
Southr_America =1;
}

The generated golang to be

const (
    Region_North_America  Region = 0
    Region_Southr_America Region = 1
)

var Region_name = map[int32]string{
    0: "North_America",
    1: "Southr_America",
}

var Region_value = map[string]int32{
    "North_America":  0,
    "Southr_America": 1,
}

How can I give some tag for enum, so that the generated

var Region_name = map[int32]string{
    0: "North America",
    1: "Southr America",
}

var Region_value = map[string]int32{
    "North America":  0,
    "Southr America": 1,
}
1 Answers

This cannot be done; if an element is added or removed, the entire structure will be broken. Therefore, you need to explicitly specify identifiers ... = 0; required

Related