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

Function ToProto

common/ast/conversion.go:44–75  ·  view source on GitHub ↗

ToProto converts an AST to a CheckedExpr protobouf.

(ast *AST)

Source from the content-addressed store, hash-verified

42
43// ToProto converts an AST to a CheckedExpr protobouf.
44func ToProto(ast *AST) (*exprpb.CheckedExpr, error) {
45 refMap := make(map[int64]*exprpb.Reference, len(ast.ReferenceMap()))
46 for id, ref := range ast.ReferenceMap() {
47 r, err := ReferenceInfoToProto(ref)
48 if err != nil {
49 return nil, err
50 }
51 refMap[id] = r
52 }
53 typeMap := make(map[int64]*exprpb.Type, len(ast.TypeMap()))
54 for id, typ := range ast.TypeMap() {
55 t, err := types.TypeToExprType(typ)
56 if err != nil {
57 return nil, err
58 }
59 typeMap[id] = t
60 }
61 e, err := ExprToProto(ast.Expr())
62 if err != nil {
63 return nil, err
64 }
65 info, err := SourceInfoToProto(ast.SourceInfo())
66 if err != nil {
67 return nil, err
68 }
69 return &exprpb.CheckedExpr{
70 Expr: e,
71 SourceInfo: info,
72 ReferenceMap: refMap,
73 TypeMap: typeMap,
74 }, nil
75}
76
77// ToAST converts a CheckedExpr protobuf to an AST instance.
78func ToAST(checked *exprpb.CheckedExpr) (*AST, error) {

Callers 4

AstToCheckedExprFunction · 0.92
TestASTCopyFunction · 0.92
TestASTJsonNamesFunction · 0.92
TestConvertASTFunction · 0.92

Calls 8

TypeToExprTypeFunction · 0.92
ReferenceInfoToProtoFunction · 0.85
ExprToProtoFunction · 0.85
SourceInfoToProtoFunction · 0.85
ReferenceMapMethod · 0.80
TypeMapMethod · 0.80
ExprMethod · 0.65
SourceInfoMethod · 0.45

Tested by 3

TestASTCopyFunction · 0.74
TestASTJsonNamesFunction · 0.74
TestConvertASTFunction · 0.74