This commit is contained in:
tfl
2024-08-27 12:23:15 +08:00
parent 77ac18c21b
commit 123c304a01
13 changed files with 105 additions and 42 deletions

View File

@@ -2,9 +2,11 @@ package message
import (
"encoding/json"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
"time"
"github.com/google/uuid"
"github.com/kakuilan/kgo"
"github.com/sirupsen/logrus"
)
// 消息类型
@@ -14,7 +16,6 @@ const (
RpcRequestFromDevice = "RpcRequestFromDevice"
RpcRequestToDevice = "RpcRequestToDevice"
UpEventMes = "Event"
AlarmMes = "Alarm"
RowMes = "Row"
TelemetryMes = "Telemetry"
AttributesMes = "Attributes"
@@ -117,6 +118,26 @@ func (meta *Metadata) GetValue(key string) any {
}
return (*meta)[key]
}
func (meta *Metadata) GetStringValue(key string) string {
if _, found := (*meta)[key]; !found {
return ""
}
return kgo.KConv.ToStr((*meta)[key])
}
func (meta *Metadata) GetIntValue(key string) int {
if _, found := (*meta)[key]; !found {
return 0
}
return kgo.KConv.ToInt((*meta)[key])
}
func (meta *Metadata) GetFloat64Value(key string) float64 {
if _, found := (*meta)[key]; !found {
return 0
}
return kgo.KConv.ToFloat((*meta)[key])
}
func (meta *Metadata) Has(key string) bool {
_, ok := (*meta)[key]