lib/prompbmarshal: code cleanup after 8aaa828ba3

This commit is contained in:
Aliaksandr Valialkin 2024-02-01 21:31:08 +02:00
parent 0e3c532bf7
commit a40fcc8aa6
No known key found for this signature in database
GPG key ID: 52C003EE2BCDB9EB
2 changed files with 64 additions and 104 deletions

View file

@ -4,61 +4,50 @@
package prompbmarshal
import (
math_bits "math/bits"
"math/bits"
)
type WriteRequest struct {
Timeseries []TimeSeries
}
func (m *WriteRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if len(m.Timeseries) > 0 {
for iNdEx := len(m.Timeseries) - 1; iNdEx >= 0; iNdEx-- {
{
size, err := m.Timeseries[iNdEx].MarshalToSizedBuffer(dAtA[:i])
func (m *WriteRequest) MarshalToSizedBuffer(dst []byte) (int, error) {
i := len(dst)
for j := len(m.Timeseries) - 1; j >= 0; j-- {
size, err := m.Timeseries[j].MarshalToSizedBuffer(dst[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarint(dAtA, i, uint64(size))
}
i = encodeVarint(dst, i, uint64(size))
i--
dAtA[i] = 0xa
dst[i] = 0xa
}
}
return len(dAtA) - i, nil
return len(dst) - i, nil
}
func encodeVarint(dAtA []byte, offset int, v uint64) int {
func encodeVarint(dst []byte, offset int, v uint64) int {
offset -= sov(v)
base := offset
for v >= 1<<7 {
dAtA[offset] = uint8(v&0x7f | 0x80)
dst[offset] = uint8(v&0x7f | 0x80)
v >>= 7
offset++
}
dAtA[offset] = uint8(v)
dst[offset] = uint8(v)
return base
}
func (m *WriteRequest) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if len(m.Timeseries) > 0 {
for _, e := range m.Timeseries {
l = e.Size()
l := e.Size()
n += 1 + l + sov(uint64(l))
}
}
return n
}
func sov(x uint64) (n int) {
return (math_bits.Len64(x|1) + 6) / 7
return (bits.Len64(x|1) + 6) / 7
}

View file

@ -4,8 +4,8 @@
package prompbmarshal
import (
encoding_binary "encoding/binary"
math "math"
"encoding/binary"
"math"
)
type Sample struct {
@ -24,89 +24,70 @@ type Label struct {
Value string
}
func (m *Sample) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
func (m *Sample) MarshalToSizedBuffer(dst []byte) (int, error) {
i := len(dst)
if m.Timestamp != 0 {
i = encodeVarint(dAtA, i, uint64(m.Timestamp))
i = encodeVarint(dst, i, uint64(m.Timestamp))
i--
dAtA[i] = 0x10
dst[i] = 0x10
}
if m.Value != 0 {
i -= 8
encoding_binary.LittleEndian.PutUint64(dAtA[i:], uint64(math.Float64bits(float64(m.Value))))
binary.LittleEndian.PutUint64(dst[i:], uint64(math.Float64bits(float64(m.Value))))
i--
dAtA[i] = 0x9
dst[i] = 0x9
}
return len(dAtA) - i, nil
return len(dst) - i, nil
}
func (m *TimeSeries) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if len(m.Samples) > 0 {
for iNdEx := len(m.Samples) - 1; iNdEx >= 0; iNdEx-- {
{
size, err := m.Samples[iNdEx].MarshalToSizedBuffer(dAtA[:i])
func (m *TimeSeries) MarshalToSizedBuffer(dst []byte) (int, error) {
i := len(dst)
for j := len(m.Samples) - 1; j >= 0; j-- {
size, err := m.Samples[j].MarshalToSizedBuffer(dst[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarint(dAtA, i, uint64(size))
}
i = encodeVarint(dst, i, uint64(size))
i--
dAtA[i] = 0x12
dst[i] = 0x12
}
}
if len(m.Labels) > 0 {
for iNdEx := len(m.Labels) - 1; iNdEx >= 0; iNdEx-- {
{
size, err := m.Labels[iNdEx].MarshalToSizedBuffer(dAtA[:i])
for j := len(m.Labels) - 1; j >= 0; j-- {
size, err := m.Labels[j].MarshalToSizedBuffer(dst[:i])
if err != nil {
return 0, err
}
i -= size
i = encodeVarint(dAtA, i, uint64(size))
}
i = encodeVarint(dst, i, uint64(size))
i--
dAtA[i] = 0xa
dst[i] = 0xa
}
}
return len(dAtA) - i, nil
return len(dst) - i, nil
}
func (m *Label) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
func (m *Label) MarshalToSizedBuffer(dst []byte) (int, error) {
i := len(dst)
if len(m.Value) > 0 {
i -= len(m.Value)
copy(dAtA[i:], m.Value)
i = encodeVarint(dAtA, i, uint64(len(m.Value)))
copy(dst[i:], m.Value)
i = encodeVarint(dst, i, uint64(len(m.Value)))
i--
dAtA[i] = 0x12
dst[i] = 0x12
}
if len(m.Name) > 0 {
i -= len(m.Name)
copy(dAtA[i:], m.Name)
i = encodeVarint(dAtA, i, uint64(len(m.Name)))
copy(dst[i:], m.Name)
i = encodeVarint(dst, i, uint64(len(m.Name)))
i--
dAtA[i] = 0xa
dst[i] = 0xa
}
return len(dAtA) - i, nil
return len(dst) - i, nil
}
func (m *Sample) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if m.Value != 0 {
n += 9
}
@ -120,20 +101,14 @@ func (m *TimeSeries) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
if len(m.Labels) > 0 {
for _, e := range m.Labels {
l = e.Size()
l := e.Size()
n += 1 + l + sov(uint64(l))
}
}
if len(m.Samples) > 0 {
for _, e := range m.Samples {
l = e.Size()
l := e.Size()
n += 1 + l + sov(uint64(l))
}
}
return n
}
@ -141,14 +116,10 @@ func (m *Label) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.Name)
if l > 0 {
if l := len(m.Name); l > 0 {
n += 1 + l + sov(uint64(l))
}
l = len(m.Value)
if l > 0 {
if l := len(m.Value); l > 0 {
n += 1 + l + sov(uint64(l))
}
return n