2024-02-01 04:33:03 +00:00
|
|
|
package prompbmarshal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2024-05-12 09:24:48 +00:00
|
|
|
|
|
|
|
"github.com/VictoriaMetrics/VictoriaMetrics/lib/slicesutil"
|
2024-02-01 04:33:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// MarshalProtobuf marshals wr to dst and returns the result.
|
|
|
|
func (wr *WriteRequest) MarshalProtobuf(dst []byte) []byte {
|
|
|
|
size := wr.Size()
|
|
|
|
dstLen := len(dst)
|
2024-05-12 09:24:48 +00:00
|
|
|
dst = slicesutil.SetLength(dst, dstLen+size)
|
2024-02-01 04:33:03 +00:00
|
|
|
n, err := wr.MarshalToSizedBuffer(dst[dstLen:])
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Errorf("BUG: unexpected error when marshaling WriteRequest: %w", err))
|
|
|
|
}
|
|
|
|
return dst[:dstLen+n]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reset resets wr.
|
|
|
|
func (wr *WriteRequest) Reset() {
|
|
|
|
wr.Timeseries = ResetTimeSeries(wr.Timeseries)
|
|
|
|
}
|
|
|
|
|
|
|
|
// ResetTimeSeries clears all the GC references from tss and returns an empty tss ready for further use.
|
|
|
|
func ResetTimeSeries(tss []TimeSeries) []TimeSeries {
|
2024-03-03 21:40:34 +00:00
|
|
|
clear(tss)
|
2024-02-01 04:33:03 +00:00
|
|
|
return tss[:0]
|
|
|
|
}
|