Open rickb777 opened 6 years ago
Thanks for the suggestion.
We've spotted a problem here:
https://github.com/gogo/protobuf/blob/master/proto/properties.go#L508
(in the code forked from golang/protobuf),
RegisterEnum() takes map[int32]string
So if we use map[ccTypeName]string, we will have problems registering our enum.
re github.com/gogo/protobuf/protoc-gen-gogo/generator/generator.go
Line 1481 is
func generateEnum
, which produces two tables, X_name and X_value, both of which are amap
. They both useint32
, which is weak typing.The enumeration that is generated has its own type derived from
int32
. If this were to use this type as the key of theX_name
map and as the value of theX_value
map, this would give stronger types. Arguably, this would be an improvement.The benefit of this change is that it would not be necessary to type-convert to/from int32 when using these tables with the enumeration values.
So line 1524 would become
And line 1537 would become
For an enumeration called, say,
ErrorCode
, the generated maps would becomeand