fix: stabilize yutong mqtt ingestion
This commit is contained in:
@@ -133,7 +133,7 @@ func rawValues(env envelope.FrameEnvelope) []any {
|
||||
messageIDInt(env.MessageID),
|
||||
eventTime,
|
||||
received,
|
||||
rawSize(env.RawHex),
|
||||
rawSizeBytes(env),
|
||||
env.RawHex,
|
||||
env.RawText,
|
||||
jsonString(env.Parsed),
|
||||
@@ -200,12 +200,15 @@ func messageIDInt(value string) int64 {
|
||||
return parsed
|
||||
}
|
||||
|
||||
func rawSize(rawHex string) int {
|
||||
rawHex = strings.TrimSpace(rawHex)
|
||||
func rawSizeBytes(env envelope.FrameEnvelope) int {
|
||||
rawHex := strings.TrimSpace(env.RawHex)
|
||||
if len(rawHex)%2 != 0 {
|
||||
return len(rawHex) / 2
|
||||
}
|
||||
return len(rawHex) / 2
|
||||
if rawHex != "" {
|
||||
return len(rawHex) / 2
|
||||
}
|
||||
return len([]byte(env.RawText))
|
||||
}
|
||||
|
||||
func jsonString(value any) string {
|
||||
|
||||
@@ -75,6 +75,18 @@ func TestWriterSkipsSparseDerivedRows(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRawSizeBytesUsesRawTextWhenHexIsEmpty(t *testing.T) {
|
||||
env := envelope.FrameEnvelope{RawText: `{"code":"0F80","data":{"speed":12}}`}
|
||||
if got, want := rawSizeBytes(env), len([]byte(env.RawText)); got != want {
|
||||
t.Fatalf("raw text size = %d, want %d", got, want)
|
||||
}
|
||||
|
||||
env.RawHex = "7E0200"
|
||||
if got, want := rawSizeBytes(env), 3; got != want {
|
||||
t.Fatalf("raw hex size = %d, want %d", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func sampleEnvelope() envelope.FrameEnvelope {
|
||||
return envelope.FrameEnvelope{
|
||||
Protocol: envelope.ProtocolJT808,
|
||||
|
||||
Reference in New Issue
Block a user