@@ -55,15 +55,16 @@ func (pi *IndexVisitor) ParseStreaming(r io.Reader) error {
55
55
return errors .Newf ("expected LEN type tag for %s" , indexFieldName (fieldNumber ))
56
56
}
57
57
lenBuf = lenBuf [:0 ]
58
- dataLen , err := readVarint (r , lenBuf )
58
+ dataLenUint , err := readVarint (r , & lenBuf )
59
+ dataLen := int (dataLenUint )
59
60
if err != nil {
60
61
return errors .Wrapf (err , "failed to read length for %s" , indexFieldName (fieldNumber ))
61
62
}
62
- if dataLen > uint64 ( cap (dataBuf ) ) {
63
+ if dataLen > cap (dataBuf ) {
63
64
dataBuf = make ([]byte , dataLen )
64
65
} else {
65
66
dataBuf = dataBuf [:0 ]
66
- for i := uint64 ( 0 ) ; i < dataLen ; i ++ {
67
+ for i := 0 ; i < dataLen ; i ++ {
67
68
dataBuf = append (dataBuf , 0 )
68
69
}
69
70
}
@@ -73,7 +74,7 @@ func (pi *IndexVisitor) ParseStreaming(r io.Reader) error {
73
74
if err != nil {
74
75
return errors .Wrapf (err , "failed to read data for %s" , indexFieldName (fieldNumber ))
75
76
}
76
- if uint64 ( numRead ) != dataLen {
77
+ if numRead != dataLen {
77
78
return errors .Newf (
78
79
"expected to read %d bytes based on LEN but read %d bytes" , dataLen , numRead )
79
80
}
@@ -115,9 +116,9 @@ const (
115
116
//
116
117
// scratchBuf should be able to accommodate any varint size
117
118
// based on its capacity, and be cleared before readVarint is called
118
- func readVarint (r io.Reader , scratchBuf []byte ) (uint64 , error ) {
119
+ func readVarint (r io.Reader , scratchBuf * []byte ) (uint64 , error ) {
119
120
nextByteBuf := make ([]byte , 1 , 1 )
120
- for i := 0 ; i < cap (scratchBuf ); i ++ {
121
+ for i := 0 ; i < cap (* scratchBuf ); i ++ {
121
122
numRead , err := r .Read (nextByteBuf )
122
123
if err != nil {
123
124
return 0 , errors .Wrapf (err , "failed to read %d-th byte of Varint. soFar: %v" , i , scratchBuf )
@@ -126,13 +127,13 @@ func readVarint(r io.Reader, scratchBuf []byte) (uint64, error) {
126
127
return 0 , errors .Newf ("failed to read %d-th byte of Varint. soFar: %v" , scratchBuf )
127
128
}
128
129
nextByte := nextByteBuf [0 ]
129
- scratchBuf = append (scratchBuf , nextByte )
130
+ * scratchBuf = append (* scratchBuf , nextByte )
130
131
if nextByte <= 127 { // https://protobuf.dev/programming-guides/encoding/#varints
131
132
// Continuation bit is not set, so Varint must've ended
132
133
break
133
134
}
134
135
}
135
- value , errCode := protowire .ConsumeVarint (scratchBuf )
136
+ value , errCode := protowire .ConsumeVarint (* scratchBuf )
136
137
if errCode < 0 {
137
138
return value , protowire .ParseError (errCode )
138
139
}
0 commit comments