1
1
package scip
2
2
3
3
import (
4
+ "context"
4
5
"io"
5
6
6
7
"github.com/cockroachdb/errors"
@@ -13,9 +14,9 @@ import (
13
14
// implementations, so adding new functions here for new fields in
14
15
// the SCIP schema would break clients. Individual functions may be nil.
15
16
type IndexVisitor struct {
16
- VisitMetadata func (* Metadata )
17
- VisitDocument func (* Document )
18
- VisitExternalSymbol func (* SymbolInformation )
17
+ VisitMetadata func (ctx context. Context , m * Metadata ) error
18
+ VisitDocument func (ctx context. Context , d * Document ) error
19
+ VisitExternalSymbol func (ctx context. Context , si * SymbolInformation ) error
19
20
}
20
21
21
22
// See https://protobuf.dev/programming-guides/encoding/#varints
@@ -24,7 +25,7 @@ const maxVarintBytes = 10
24
25
// ParseStreaming processes an index by incrementally reading input from the io.Reader.
25
26
//
26
27
// Parsing takes place at Document granularity for ease of use.
27
- func (pi * IndexVisitor ) ParseStreaming (r io.Reader ) error {
28
+ func (pi * IndexVisitor ) ParseStreaming (ctx context. Context , r io.Reader ) error {
28
29
// The tag is encoded as a varint with value: (field_number << 3) | wire_type
29
30
// Varints < 128 fit in 1 byte, which means 4 bits are available for field
30
31
// numbers. The Index type has less than 15 fields, so the tag will fit in 1 byte.
@@ -84,23 +85,29 @@ func (pi *IndexVisitor) ParseStreaming(r io.Reader) error {
84
85
if err := proto .Unmarshal (dataBuf , & m ); err != nil {
85
86
return errors .Wrapf (err , "failed to read %s" , indexFieldName (fieldNumber ))
86
87
}
87
- pi .VisitMetadata (& m )
88
+ if err := pi .VisitMetadata (ctx , & m ); err != nil {
89
+ return err
90
+ }
88
91
}
89
92
} else if fieldNumber == documentsFieldNumber {
90
93
if pi .VisitDocument != nil {
91
94
d := Document {}
92
95
if err := proto .Unmarshal (dataBuf , & d ); err != nil {
93
96
return errors .Wrapf (err , "failed to read %s" , indexFieldName (fieldNumber ))
94
97
}
95
- pi .VisitDocument (& d )
98
+ if err := pi .VisitDocument (ctx , & d ); err != nil {
99
+ return err
100
+ }
96
101
}
97
102
} else if fieldNumber == externalSymbolsFieldNumber {
98
103
if pi .VisitExternalSymbol != nil {
99
104
s := SymbolInformation {}
100
105
if err := proto .Unmarshal (dataBuf , & s ); err != nil {
101
106
return errors .Wrapf (err , "failed to read %s" , indexFieldName (fieldNumber ))
102
107
}
103
- pi .VisitExternalSymbol (& s )
108
+ if err := pi .VisitExternalSymbol (ctx , & s ); err != nil {
109
+ return err
110
+ }
104
111
}
105
112
} else {
106
113
return errors .Newf (
0 commit comments