MCPcopy
hub / github.com/google/mangle / ProtoEnumToConstant

Function ProtoEnumToConstant

proto2struct/proto2struct.go:124–130  ·  view source on GitHub ↗

ProtoEnumToConstant uses reflection to convert a proto field value to a Mangle value.

(ed protoreflect.EnumDescriptor, val protoreflect.Value)

Source from the content-addressed store, hash-verified

122
123// ProtoEnumToConstant uses reflection to convert a proto field value to a Mangle value.
124func 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}

Callers 1

ProtoValueToConstantFunction · 0.85

Calls 1

NameFunction · 0.92

Tested by

no test coverage detected