wp
This commit is contained in:
@@ -4,8 +4,8 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
diploma "gordenko.dev/dima/qb"
|
||||
"gordenko.dev/dima/qb/bin"
|
||||
bin "gordenko.dev/dima/bin/little"
|
||||
"gordenko.dev/dima/qb"
|
||||
"gordenko.dev/dima/qb/bufreader"
|
||||
)
|
||||
|
||||
@@ -72,7 +72,7 @@ func ErrorCodeToText(code uint16) string {
|
||||
|
||||
type Metric struct {
|
||||
MetricID uint32
|
||||
MetricType diploma.MetricType
|
||||
MetricType qb.MetricType
|
||||
FracDigits int
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ func ReadListCurrentValuesReq(r *bufreader.BufferedReader) (m ListCurrentValuesR
|
||||
|
||||
type AddMetricReq struct {
|
||||
MetricID uint32
|
||||
MetricType diploma.MetricType
|
||||
MetricType qb.MetricType
|
||||
FracDigits int
|
||||
}
|
||||
|
||||
@@ -175,8 +175,8 @@ func ReadAddMetricReq(r *bufreader.BufferedReader) (m AddMetricReq, err error) {
|
||||
}
|
||||
|
||||
func UnpackAddMetricReq(arr []byte) (m AddMetricReq) {
|
||||
m.MetricID = bin.GetUint32(arr)
|
||||
m.MetricType = diploma.MetricType(arr[4])
|
||||
m.MetricID, _ = bin.GetUint32(arr)
|
||||
m.MetricType = qb.MetricType(arr[4])
|
||||
m.FracDigits = int(arr[5])
|
||||
return
|
||||
}
|
||||
@@ -209,8 +209,8 @@ func ReadDeleteMeasuresReq(r *bufreader.BufferedReader) (m DeleteMeasuresReq, er
|
||||
}
|
||||
|
||||
func UnpackDeleteMeasuresReq(arr []byte) (m DeleteMeasuresReq) {
|
||||
m.MetricID = bin.GetUint32(arr)
|
||||
m.Since = bin.GetUint32(arr[4:])
|
||||
m.MetricID, _ = bin.GetUint32(arr)
|
||||
m.Since, _ = bin.GetUint32(arr[4:])
|
||||
return
|
||||
}
|
||||
|
||||
@@ -230,9 +230,9 @@ func ReadAppendMeasureReq(r *bufreader.BufferedReader) (m AppendMeasureReq, err
|
||||
}
|
||||
|
||||
func UnpackAppendMeasureReq(arr []byte) (m AppendMeasureReq) {
|
||||
m.MetricID = bin.GetUint32(arr)
|
||||
m.Timestamp = bin.GetUint32(arr[4:])
|
||||
m.Value = bin.GetFloat64(arr[8:])
|
||||
m.MetricID, _ = bin.GetUint32(arr)
|
||||
m.Timestamp, _ = bin.GetUint32(arr[4:])
|
||||
m.Value, _ = bin.GetFloat64(arr[8:])
|
||||
return
|
||||
}
|
||||
|
||||
@@ -253,8 +253,8 @@ func ReadAppendMeasuresReq(r *bufreader.BufferedReader) (m AppendMeasuresReq, er
|
||||
return
|
||||
}
|
||||
|
||||
m.MetricID = bin.GetUint32(prefix[0:])
|
||||
qty := bin.GetUint16(prefix[4:])
|
||||
m.MetricID, _ = bin.GetUint32(prefix[0:])
|
||||
qty, _ := bin.GetUint16(prefix[4:])
|
||||
|
||||
for i := range int(qty) {
|
||||
var measure Measure
|
||||
@@ -280,21 +280,25 @@ type MetricMeasure struct {
|
||||
}
|
||||
|
||||
func ReadAppendMeasurePerMetricReq(r *bufreader.BufferedReader) (measures []MetricMeasure, err error) {
|
||||
qty, err := bin.ReadUint16(r)
|
||||
count, err := bin.ReadUint16(r)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var tmp = make([]byte, 16)
|
||||
for range int(qty) {
|
||||
err = bin.ReadNInto(r, tmp)
|
||||
for range count {
|
||||
var m MetricMeasure
|
||||
m.MetricID, err = bin.ReadUint32(r)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
measures = append(measures, MetricMeasure{
|
||||
MetricID: bin.GetUint32(tmp[0:]),
|
||||
Timestamp: bin.GetUint32(tmp[4:]),
|
||||
Value: bin.GetFloat64(tmp[8:]),
|
||||
})
|
||||
m.Timestamp, err = bin.ReadUint32(r)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
m.Value, err = bin.ReadFloat64(r)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
measures = append(measures, m)
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -341,9 +345,9 @@ func ReadListInstantMeasuresReq(r *bufreader.BufferedReader) (m ListInstantMeasu
|
||||
}
|
||||
|
||||
func UnpackListInstantMeasuresReq(arr []byte) (m ListInstantMeasuresReq) {
|
||||
m.MetricID = bin.GetUint32(arr[0:])
|
||||
m.Since = bin.GetUint32(arr[4:])
|
||||
m.Until = bin.GetUint32(arr[8:])
|
||||
m.MetricID, _ = bin.GetUint32(arr[0:])
|
||||
m.Since, _ = bin.GetUint32(arr[4:])
|
||||
m.Until, _ = bin.GetUint32(arr[8:])
|
||||
return
|
||||
}
|
||||
|
||||
@@ -363,9 +367,9 @@ func ReadListCumulativeMeasuresReq(r *bufreader.BufferedReader) (m ListCumulativ
|
||||
}
|
||||
|
||||
func UnpackListCumulativeMeasuresReq(arr []byte) (m ListCumulativeMeasuresReq) {
|
||||
m.MetricID = bin.GetUint32(arr)
|
||||
m.Since = bin.GetUint32(arr[4:])
|
||||
m.Until = bin.GetUint32(arr[8:])
|
||||
m.MetricID, _ = bin.GetUint32(arr)
|
||||
m.Since, _ = bin.GetUint32(arr[4:])
|
||||
m.Until, _ = bin.GetUint32(arr[8:])
|
||||
return
|
||||
}
|
||||
|
||||
@@ -373,7 +377,7 @@ type ListInstantPeriodsReq struct {
|
||||
MetricID uint32
|
||||
Since TimeBound
|
||||
Until TimeBound
|
||||
GroupBy diploma.GroupBy
|
||||
GroupBy qb.GroupBy
|
||||
AggregateFuncs byte
|
||||
FirstHourOfDay int
|
||||
}
|
||||
@@ -388,18 +392,20 @@ func ReadListInstantPeriodsReq(r *bufreader.BufferedReader) (m ListInstantPeriod
|
||||
}
|
||||
|
||||
func UnpackListInstantPeriodsReq(arr []byte) (m ListInstantPeriodsReq) {
|
||||
m.MetricID = bin.GetUint32(arr)
|
||||
m.MetricID, _ = bin.GetUint32(arr)
|
||||
sinceYear, _ := bin.GetUint16(arr[4:])
|
||||
untilYear, _ := bin.GetUint16(arr[8:])
|
||||
m.Since = TimeBound{
|
||||
Year: int(bin.GetUint16(arr[4:])),
|
||||
Year: int(sinceYear),
|
||||
Month: time.Month(arr[6]),
|
||||
Day: int(arr[7]),
|
||||
}
|
||||
m.Until = TimeBound{
|
||||
Year: int(bin.GetUint16(arr[8:])),
|
||||
Year: int(untilYear),
|
||||
Month: time.Month(arr[10]),
|
||||
Day: int(arr[11]),
|
||||
}
|
||||
m.GroupBy = diploma.GroupBy(arr[12])
|
||||
m.GroupBy = qb.GroupBy(arr[12])
|
||||
m.AggregateFuncs = arr[13]
|
||||
m.FirstHourOfDay = int(arr[14])
|
||||
return
|
||||
@@ -409,7 +415,7 @@ type ListCumulativePeriodsReq struct {
|
||||
MetricID uint32
|
||||
Since TimeBound
|
||||
Until TimeBound
|
||||
GroupBy diploma.GroupBy
|
||||
GroupBy qb.GroupBy
|
||||
FirstHourOfDay int
|
||||
}
|
||||
|
||||
@@ -423,18 +429,20 @@ func ReadListCumulativePeriodsReq(r *bufreader.BufferedReader) (m ListCumulative
|
||||
}
|
||||
|
||||
func UnpackListCumulativePeriodsReq(arr []byte) (m ListCumulativePeriodsReq) {
|
||||
m.MetricID = bin.GetUint32(arr[0:])
|
||||
m.MetricID, _ = bin.GetUint32(arr[0:])
|
||||
sinceYear, _ := bin.GetUint16(arr[4:])
|
||||
untilYear, _ := bin.GetUint16(arr[8:])
|
||||
m.Since = TimeBound{
|
||||
Year: int(bin.GetUint16(arr[4:])),
|
||||
Year: int(sinceYear),
|
||||
Month: time.Month(arr[6]),
|
||||
Day: int(arr[7]),
|
||||
}
|
||||
m.Until = TimeBound{
|
||||
Year: int(bin.GetUint16(arr[8:])),
|
||||
Year: int(untilYear),
|
||||
Month: time.Month(arr[10]),
|
||||
Day: int(arr[11]),
|
||||
}
|
||||
m.GroupBy = diploma.GroupBy(arr[12])
|
||||
m.GroupBy = qb.GroupBy(arr[12])
|
||||
m.FirstHourOfDay = int(arr[13])
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user