ProtoEnumToConstant uses reflection to convert a proto field value to a Mangle value.
(ed protoreflect.EnumDescriptor, val protoreflect.Value)
| 122 | |
| 123 | // ProtoEnumToConstant uses reflection to convert a proto field value to a Mangle value. |
| 124 | func ProtoEnumToConstant(ed protoreflect.EnumDescriptor, val protoreflect.Value) (ast.Constant, error) { |
| 125 | enumValueDescr := ed.Values().ByNumber(val.Enum()) |
| 126 | if enumValueDescr == nil { |
| 127 | return ast.Constant{}, fmt.Errorf("could not find enum value %d in %v", val.Enum(), ed) |
| 128 | } |
| 129 | return ast.Name("/" + string(ed.Name()) + "/" + string(enumValueDescr.Name())) |
| 130 | } |
no test coverage detected