MCPcopy Create free account
hub / github.com/cel-expr/cel-go / ProtoConstantAsVal

Function ProtoConstantAsVal

common/ast/conversion.go:681–699  ·  view source on GitHub ↗

ProtoConstantAsVal converts a canonical celpb.Constant protobuf to a CEL-native ref.Val.

(c *celpb.Constant)

Source from the content-addressed store, hash-verified

679
680// ProtoConstantAsVal converts a canonical celpb.Constant protobuf to a CEL-native ref.Val.
681func ProtoConstantAsVal(c *celpb.Constant) (ref.Val, error) {
682 switch c.GetConstantKind().(type) {
683 case *celpb.Constant_BoolValue:
684 return types.Bool(c.GetBoolValue()), nil
685 case *celpb.Constant_BytesValue:
686 return types.Bytes(c.GetBytesValue()), nil
687 case *celpb.Constant_DoubleValue:
688 return types.Double(c.GetDoubleValue()), nil
689 case *celpb.Constant_Int64Value:
690 return types.Int(c.GetInt64Value()), nil
691 case *celpb.Constant_NullValue:
692 return types.NullValue, nil
693 case *celpb.Constant_StringValue:
694 return types.String(c.GetStringValue()), nil
695 case *celpb.Constant_Uint64Value:
696 return types.Uint(c.GetUint64Value()), nil
697 }
698 return nil, fmt.Errorf("unsupported constant kind: %v", c.GetConstantKind())
699}
700
701func convertProto(src, dst proto.Message) error {
702 pb, err := proto.Marshal(src)

Callers 2

ProtoAsDeclarationFunction · 0.92
AlphaProtoConstantAsValFunction · 0.85

Calls 6

BoolTypeAlias · 0.92
BytesTypeAlias · 0.92
DoubleTypeAlias · 0.92
IntTypeAlias · 0.92
StringTypeAlias · 0.92
UintTypeAlias · 0.92

Tested by

no test coverage detected