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

Function ProtoToSourceInfo

common/ast/conversion.go:573–609  ·  view source on GitHub ↗

ProtoToSourceInfo deserializes the protobuf into a native SourceInfo value.

(info *exprpb.SourceInfo)

Source from the content-addressed store, hash-verified

571
572// ProtoToSourceInfo deserializes the protobuf into a native SourceInfo value.
573func ProtoToSourceInfo(info *exprpb.SourceInfo) (*SourceInfo, error) {
574 sourceInfo := &SourceInfo{
575 syntax: info.GetSyntaxVersion(),
576 desc: info.GetLocation(),
577 lines: info.GetLineOffsets(),
578 offsetRanges: make(map[int64]OffsetRange, len(info.GetPositions())),
579 macroCalls: make(map[int64]Expr, len(info.GetMacroCalls())),
580 }
581 for id, offset := range info.GetPositions() {
582 sourceInfo.SetOffsetRange(id, OffsetRange{Start: offset, Stop: offset})
583 }
584 for id, e := range info.GetMacroCalls() {
585 call, err := ProtoToExpr(e)
586 if err != nil {
587 return nil, err
588 }
589 sourceInfo.SetMacroCall(id, call)
590 }
591 for _, pbExt := range info.GetExtensions() {
592 var components []ExtensionComponent
593 for _, c := range pbExt.GetAffectedComponents() {
594 comp, found := pbComponentMap[*c.Enum()]
595 if found {
596 components = append(components, comp)
597 }
598 }
599 sourceInfo.AddExtension(NewExtension(
600 pbExt.GetId(),
601 NewExtensionVersion(
602 pbExt.GetVersion().GetMajor(),
603 pbExt.GetVersion().GetMinor(),
604 ),
605 components...,
606 ))
607 }
608 return sourceInfo, nil
609}
610
611// ReferenceInfoToProto converts a ReferenceInfo instance to a protobuf Reference suitable for serialization.
612func ReferenceInfoToProto(info *ReferenceInfo) (*exprpb.Reference, error) {

Callers 4

TestASTNilSafetyFunction · 0.92
TestSourceInfoNilSafetyFunction · 0.92
ToASTFunction · 0.85

Calls 9

SetOffsetRangeMethod · 0.95
SetMacroCallMethod · 0.95
AddExtensionMethod · 0.95
ProtoToExprFunction · 0.85
NewExtensionVersionFunction · 0.85
NewExtensionFunction · 0.70
GetLocationMethod · 0.65
GetIdMethod · 0.65
EnumMethod · 0.45

Tested by 2

TestASTNilSafetyFunction · 0.74
TestSourceInfoNilSafetyFunction · 0.74