Original post

Hi, I am serializing arbitrary Dynamo attribute (type S: <string>), a string representing an enum type as defined in a proto definition, to the arbitrary protobuf message. (it is a requirement to persist the enum as the string value rather than the numeric value). I have the string value from Dynamo, I need to convert this string value to the numeric representation of this enum type as defined in the protobuf definition.

In Python there are methods ‘values_by_number’ and ‘values_by_name’ which help in this regard: https://developers.google.com/protocol-buffers/docs/reference/python/google.protobuf.descriptor.EnumDescriptor-class

I cannot figure out how to do this in . I realize the generated .pb. file has a map definition in there which will convert from string enum to numeric enum (and vice versa too). Since I am writing arbitrary code, I do not know the name of this map variable so I cannot realistically refer to it.

I’m also heavily using reflection to walk through the proto fields and assign them.

Any help is appreciated.

submitted by /u/purified3
[link] [comments]