ProtoToSourceInfo deserializes the protobuf into a native SourceInfo value.
(info *exprpb.SourceInfo)
| 571 | |
| 572 | // ProtoToSourceInfo deserializes the protobuf into a native SourceInfo value. |
| 573 | func 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. |
| 612 | func ReferenceInfoToProto(info *ReferenceInfo) (*exprpb.Reference, error) { |