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

Function ExprValueAsProto

cel/io.go:149–176  ·  view source on GitHub ↗

ExprValueAsProto converts between ref.Val and cel.expr.ExprValue. The result ExprValue is the serialized proto form.

(res ref.Val)

Source from the content-addressed store, hash-verified

147// ExprValueAsProto converts between ref.Val and cel.expr.ExprValue.
148// The result ExprValue is the serialized proto form.
149func ExprValueAsProto(res ref.Val) (*celpb.ExprValue, error) {
150 switch res := res.(type) {
151 case *types.Unknown:
152 return &celpb.ExprValue{
153 Kind: &celpb.ExprValue_Unknown{
154 Unknown: &celpb.UnknownSet{
155 Exprs: res.IDs(),
156 },
157 }}, nil
158 case *types.Err:
159 return &celpb.ExprValue{
160 Kind: &celpb.ExprValue_Error{
161 Error: &celpb.ErrorSet{
162 // Keeping the error code as UNKNOWN since there's no error codes associated with
163 // Cel-Go runtime errors.
164 Errors: []*celpb.Status{{Code: 2, Message: res.Error()}},
165 },
166 },
167 }, nil
168 default:
169 val, err := ValueAsProto(res)
170 if err != nil {
171 return nil, err
172 }
173 return &celpb.ExprValue{
174 Kind: &celpb.ExprValue_Value{Value: val}}, nil
175 }
176}
177
178// ValueAsProto converts between ref.Val and cel.expr.Value.
179// The result Value is the serialized proto form. The ref.Val must not be error or unknown.

Callers 2

ExprValueAsAlphaProtoFunction · 0.85
TestRefValToExprValueFunction · 0.85

Calls 3

ValueAsProtoFunction · 0.85
IDsMethod · 0.65
ErrorMethod · 0.45

Tested by 1

TestRefValToExprValueFunction · 0.68