feat(go): publish realtime fields stream
This commit is contained in:
@@ -22,6 +22,51 @@ type RealtimeKVField struct {
|
||||
EventID string
|
||||
}
|
||||
|
||||
func BuildFieldsEnvelope(env envelope.FrameEnvelope) (envelope.FrameEnvelope, bool) {
|
||||
if !envelope.IsRealtimeTelemetryFrame(env) {
|
||||
return envelope.FrameEnvelope{}, false
|
||||
}
|
||||
rows := realtimeKVFields(env, env.Parsed)
|
||||
fields := make(map[string]any, len(rows)+len(env.Fields))
|
||||
for _, row := range rows {
|
||||
key := row.Domain
|
||||
if strings.TrimSpace(row.Field) != "" {
|
||||
key += "." + row.Field
|
||||
}
|
||||
fields[key] = row.Value
|
||||
}
|
||||
for key, value := range env.Fields {
|
||||
if strings.TrimSpace(key) != "" {
|
||||
fields[key] = value
|
||||
}
|
||||
}
|
||||
if len(fields) == 0 {
|
||||
return envelope.FrameEnvelope{}, false
|
||||
}
|
||||
out := envelope.FrameEnvelope{
|
||||
EventID: env.StableEventID() + ":fields",
|
||||
TraceID: env.TraceID,
|
||||
Protocol: env.Protocol,
|
||||
MessageID: env.MessageID,
|
||||
Sequence: env.Sequence,
|
||||
VIN: env.VIN,
|
||||
VehicleKeyHint: env.VehicleKeyHint,
|
||||
Phone: env.Phone,
|
||||
DeviceID: env.DeviceID,
|
||||
Plate: env.Plate,
|
||||
SourceEndpoint: env.SourceEndpoint,
|
||||
EventTimeMS: env.EventTimeMS,
|
||||
ReceivedAtMS: env.ReceivedAtMS,
|
||||
Fields: fields,
|
||||
Parsed: map[string]any{
|
||||
"source_event_id": env.StableEventID(),
|
||||
"field_mapping": realtimeFieldMappingVersion,
|
||||
},
|
||||
ParseStatus: envelope.ParseOK,
|
||||
}
|
||||
return out, true
|
||||
}
|
||||
|
||||
type protocolFieldMapping struct {
|
||||
Prefix string
|
||||
GBDataUnits bool
|
||||
|
||||
Reference in New Issue
Block a user