@@ -247,10 +247,12 @@ func splitYAMLDocument(data []byte, atEOF bool) (advance int, token []byte, err
247
247
// finding a non-YAML-delimited series of objects), it will not switch to YAML.
248
248
// Once it switches to YAML it will not switch back to JSON.
249
249
type YAMLOrJSONDecoder struct {
250
- json * json.Decoder
251
- yaml * YAMLToJSONDecoder
252
- stream * StreamReader
253
- count int // how many objects have been decoded
250
+ json * json.Decoder
251
+ jsonConsumed int64 // of the stream total, how much was JSON?
252
+ yaml * YAMLToJSONDecoder
253
+ yamlConsumed int64 // of the stream total, how much was YAML?
254
+ stream * StreamReader
255
+ count int // how many objects have been decoded
254
256
}
255
257
256
258
type JSONSyntaxError struct {
@@ -299,8 +301,10 @@ func (d *YAMLOrJSONDecoder) Decode(into interface{}) error {
299
301
if d .json != nil {
300
302
err := d .json .Decode (into )
301
303
if err == nil {
302
- d .stream .Consume (int (d .json .InputOffset ()) - d .stream .Consumed ())
303
304
d .count ++
305
+ consumed := d .json .InputOffset () - d .jsonConsumed
306
+ d .stream .Consume (int (consumed ))
307
+ d .jsonConsumed += consumed
304
308
return nil
305
309
}
306
310
if err == io .EOF { //nolint:errorlint
@@ -334,7 +338,9 @@ func (d *YAMLOrJSONDecoder) Decode(into interface{}) error {
334
338
if d .yaml != nil {
335
339
err := d .yaml .Decode (into )
336
340
if err == nil {
337
- d .stream .Consume (d .yaml .InputOffset () - d .stream .Consumed ())
341
+ consumed := int64 (d .yaml .InputOffset ()) - d .yamlConsumed
342
+ d .stream .Consume (int (consumed ))
343
+ d .yamlConsumed += consumed
338
344
d .count ++
339
345
return nil
340
346
}
@@ -375,6 +381,7 @@ func (d *YAMLOrJSONDecoder) consumeWhitespace() error {
375
381
if err == io .EOF { //nolint:errorlint
376
382
break
377
383
}
384
+ consumed += sz
378
385
}
379
386
return io .EOF
380
387
}
0 commit comments