ProtoConstantAsVal converts a canonical celpb.Constant protobuf to a CEL-native ref.Val.
(c *celpb.Constant)
| 679 | |
| 680 | // ProtoConstantAsVal converts a canonical celpb.Constant protobuf to a CEL-native ref.Val. |
| 681 | func 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 | |
| 701 | func convertProto(src, dst proto.Message) error { |
| 702 | pb, err := proto.Marshal(src) |