(histograms []RefHistogramSample, b []byte)
| 1083 | } |
| 1084 | |
| 1085 | func (*Encoder) histogramSamplesV1(histograms []RefHistogramSample, b []byte) ([]byte, []RefHistogramSample) { |
| 1086 | buf := encoding.Encbuf{B: b} |
| 1087 | buf.PutByte(byte(HistogramSamples)) |
| 1088 | |
| 1089 | if len(histograms) == 0 { |
| 1090 | return buf.Get(), nil |
| 1091 | } |
| 1092 | var customBucketHistograms []RefHistogramSample |
| 1093 | |
| 1094 | // Store base timestamp and base reference number of first histogram. |
| 1095 | // All histograms encode their timestamp and ref as delta to those. |
| 1096 | first := histograms[0] |
| 1097 | buf.PutBE64(uint64(first.Ref)) |
| 1098 | buf.PutBE64int64(first.T) |
| 1099 | |
| 1100 | for _, h := range histograms { |
| 1101 | if h.H.UsesCustomBuckets() { |
| 1102 | customBucketHistograms = append(customBucketHistograms, h) |
| 1103 | continue |
| 1104 | } |
| 1105 | buf.PutVarint64(int64(h.Ref) - int64(first.Ref)) |
| 1106 | buf.PutVarint64(h.T - first.T) |
| 1107 | |
| 1108 | EncodeHistogram(&buf, h.H) |
| 1109 | } |
| 1110 | |
| 1111 | // Reset buffer if only custom bucket histograms existed in list of histogram samples. |
| 1112 | if len(histograms) == len(customBucketHistograms) { |
| 1113 | buf.Reset() |
| 1114 | } |
| 1115 | |
| 1116 | return buf.Get(), customBucketHistograms |
| 1117 | } |
| 1118 | |
| 1119 | // histogramSamplesV2 encodes the given histogram samples. |
| 1120 | func (*Encoder) histogramSamplesV2(histograms []RefHistogramSample, b []byte) []byte { |
no test coverage detected