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

Function ExprToProto

common/ast/conversion.go:282–312  ·  view source on GitHub ↗

ExprToProto serializes an ast.Expr value to a protobuf Expr representation.

(e Expr)

Source from the content-addressed store, hash-verified

280
281// ExprToProto serializes an ast.Expr value to a protobuf Expr representation.
282func ExprToProto(e Expr) (*exprpb.Expr, error) {
283 if e == nil {
284 return &exprpb.Expr{}, nil
285 }
286 switch e.Kind() {
287 case CallKind:
288 return protoCall(e.ID(), e.AsCall())
289 case ComprehensionKind:
290 return protoComprehension(e.ID(), e.AsComprehension())
291 case IdentKind:
292 return protoIdent(e.ID(), e.AsIdent())
293 case ListKind:
294 return protoList(e.ID(), e.AsList())
295 case LiteralKind:
296 return protoLiteral(e.ID(), e.AsLiteral())
297 case MapKind:
298 return protoMap(e.ID(), e.AsMap())
299 case SelectKind:
300 return protoSelect(e.ID(), e.AsSelect())
301 case StructKind:
302 return protoStruct(e.ID(), e.AsStruct())
303 case UnspecifiedExprKind:
304 // Handle the case where a macro reference may be getting translated.
305 // A nested macro 'pointer' is a non-zero expression id with no kind set.
306 if e.ID() != 0 {
307 return &exprpb.Expr{Id: e.ID()}, nil
308 }
309 return &exprpb.Expr{}, nil
310 }
311 return nil, fmt.Errorf("unsupported expr kind: %v", e)
312}
313
314// EntryExprToProto converts an ast.EntryExpr to a protobuf CreateStruct entry
315func EntryExprToProto(e EntryExpr) (*exprpb.Expr_CreateStruct_Entry, error) {

Callers 13

TestExprHelperCopyFunction · 0.92
TestUnparseFunction · 0.92
adaptToProtoFunction · 0.92
TestConvertExprFunction · 0.92
ToProtoFunction · 0.85
protoCallFunction · 0.85
protoComprehensionFunction · 0.85
protoListFunction · 0.85
protoMapEntryFunction · 0.85
protoSelectFunction · 0.85
protoStructFieldFunction · 0.85

Calls 15

protoCallFunction · 0.85
protoComprehensionFunction · 0.85
protoIdentFunction · 0.85
protoListFunction · 0.85
protoLiteralFunction · 0.85
protoSelectFunction · 0.85
protoStructFunction · 0.85
protoMapFunction · 0.70
KindMethod · 0.65
IDMethod · 0.65
AsCallMethod · 0.65
AsComprehensionMethod · 0.65

Tested by 4

TestExprHelperCopyFunction · 0.74
TestUnparseFunction · 0.74
TestConvertExprFunction · 0.74