samplesV2 appends samples in rec to the given slice using the V2 algorithm, which is more efficient and supports ST (See Encoder.samplesV2 definition).
(dec *encoding.Decbuf, samples []RefSample)
| 374 | // samplesV2 appends samples in rec to the given slice using the V2 algorithm, |
| 375 | // which is more efficient and supports ST (See Encoder.samplesV2 definition). |
| 376 | func (*Decoder) samplesV2(dec *encoding.Decbuf, samples []RefSample) ([]RefSample, error) { |
| 377 | if dec.Len() == 0 { |
| 378 | return samples, nil |
| 379 | } |
| 380 | // Allow 1 byte for each varint and 8 for the value; the output slice must be at least that big. |
| 381 | if minSize := dec.Len() / (1 + 1 + 8); cap(samples) < minSize { |
| 382 | samples = make([]RefSample, 0, minSize) |
| 383 | } |
| 384 | var firstT, firstST int64 |
| 385 | for len(dec.B) > 0 && dec.Err() == nil { |
| 386 | var prev RefSample |
| 387 | var ref, t, st int64 |
| 388 | var val uint64 |
| 389 | |
| 390 | if len(samples) == 0 { |
| 391 | ref = dec.Varint64() |
| 392 | firstT = dec.Varint64() |
| 393 | t = firstT |
| 394 | st = dec.Varint64() |
| 395 | firstST = st |
| 396 | } else { |
| 397 | prev = samples[len(samples)-1] |
| 398 | ref = int64(prev.Ref) + dec.Varint64() |
| 399 | t = firstT + dec.Varint64() |
| 400 | st = readSTMarker(dec, prev.ST, firstST) |
| 401 | } |
| 402 | |
| 403 | val = dec.Be64() |
| 404 | samples = append(samples, RefSample{ |
| 405 | Ref: chunks.HeadSeriesRef(ref), |
| 406 | ST: st, |
| 407 | T: t, |
| 408 | V: math.Float64frombits(val), |
| 409 | }) |
| 410 | } |
| 411 | |
| 412 | if dec.Err() != nil { |
| 413 | return nil, fmt.Errorf("decode error after %d samples: %w", len(samples), dec.Err()) |
| 414 | } |
| 415 | if len(dec.B) > 0 { |
| 416 | return nil, fmt.Errorf("unexpected %d bytes left in entry", len(dec.B)) |
| 417 | } |
| 418 | return samples, nil |
| 419 | } |
| 420 | |
| 421 | func readSTMarker(buf *encoding.Decbuf, prevST, firstST int64) int64 { |
| 422 | stMarker := buf.Byte() |
no test coverage detected