2020-02-23 12:35:47 +01:00
|
|
|
package prompbmarshal
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
|
|
|
// MarshalWriteRequest marshals wr to dst and returns the result.
|
|
|
|
func MarshalWriteRequest(dst []byte, wr *WriteRequest) []byte {
|
|
|
|
size := wr.Size()
|
|
|
|
dstLen := len(dst)
|
|
|
|
if n := size - (cap(dst) - dstLen); n > 0 {
|
|
|
|
dst = append(dst[:cap(dst)], make([]byte, n)...)
|
|
|
|
}
|
|
|
|
dst = dst[:dstLen+size]
|
|
|
|
n, err := wr.MarshalToSizedBuffer(dst[dstLen:])
|
|
|
|
if err != nil {
|
|
|
|
panic(fmt.Errorf("BUG: unexpected error when marshaling WriteRequest: %s", err))
|
|
|
|
}
|
|
|
|
return dst[:dstLen+n]
|
|
|
|
}
|
|
|
|
|
|
|
|
// ResetWriteRequest resets wr.
|
|
|
|
func ResetWriteRequest(wr *WriteRequest) {
|
2020-05-12 21:01:47 +02:00
|
|
|
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 {
|
|
|
|
for i := range tss {
|
|
|
|
ts := tss[i]
|
2020-02-23 12:35:47 +01:00
|
|
|
ts.Labels = nil
|
|
|
|
ts.Samples = nil
|
|
|
|
}
|
2020-05-12 21:01:47 +02:00
|
|
|
return tss[:0]
|
2020-02-23 12:35:47 +01:00
|
|
|
}
|