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

Function ExprValueAsProto

cel/io.go:173–200  ·  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

171// ExprValueAsProto converts between ref.Val and cel.expr.ExprValue.
172// The result ExprValue is the serialized proto form.
173func ExprValueAsProto(res ref.Val) (*celpb.ExprValue, error) {
174 switch res := res.(type) {
175 case *types.Unknown:
176 return &celpb.ExprValue{
177 Kind: &celpb.ExprValue_Unknown{
178 Unknown: &celpb.UnknownSet{
179 Exprs: res.IDs(),
180 },
181 }}, nil
182 case *types.Err:
183 return &celpb.ExprValue{
184 Kind: &celpb.ExprValue_Error{
185 Error: &celpb.ErrorSet{
186 // Keeping the error code as UNKNOWN since there's no error codes associated with
187 // Cel-Go runtime errors.
188 Errors: []*celpb.Status{{Code: 2, Message: res.Error()}},
189 },
190 },
191 }, nil
192 default:
193 val, err := ValueAsProto(res)
194 if err != nil {
195 return nil, err
196 }
197 return &celpb.ExprValue{
198 Kind: &celpb.ExprValue_Value{Value: val}}, nil
199 }
200}
201
202// ValueAsProto converts between ref.Val and cel.expr.Value.
203// 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