fix(go): flatten jt808 additional fields
This commit is contained in:
@@ -61,7 +61,7 @@ func (r *Repository) Update(ctx context.Context, env envelope.FrameEnvelope) err
|
||||
protocolSnapshot.VIN = vin
|
||||
}
|
||||
mergeFields(&protocolSnapshot, env.Fields, eventMS)
|
||||
protocolSnapshot.Parsed = mergeParsed(protocolSnapshot.Parsed, env.Parsed)
|
||||
protocolSnapshot.Parsed = mergeParsedForProtocol(env.Protocol, protocolSnapshot.Parsed, env.Parsed)
|
||||
if eventMS >= protocolSnapshot.EventTimeMS {
|
||||
protocolSnapshot.EventTimeMS = eventMS
|
||||
protocolSnapshot.EventID = env.StableEventID()
|
||||
@@ -290,6 +290,27 @@ func mergeParsed(existing map[string]any, incoming map[string]any) map[string]an
|
||||
return out
|
||||
}
|
||||
|
||||
func mergeParsedForProtocol(protocol envelope.Protocol, existing map[string]any, incoming map[string]any) map[string]any {
|
||||
out := mergeParsed(existing, incoming)
|
||||
for _, key := range replaceParsedKeys(protocol, incoming) {
|
||||
out[key] = cloneAny(incoming[key])
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func replaceParsedKeys(protocol envelope.Protocol, incoming map[string]any) []string {
|
||||
keys := make([]string, 0, 2)
|
||||
if _, ok := incoming["header"]; ok {
|
||||
keys = append(keys, "header")
|
||||
}
|
||||
if protocol == envelope.ProtocolJT808 {
|
||||
if _, ok := incoming["location"]; ok {
|
||||
keys = append(keys, "location")
|
||||
}
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
func mergeAny(existing any, incoming any) any {
|
||||
switch incomingTyped := incoming.(type) {
|
||||
case map[string]any:
|
||||
|
||||
Reference in New Issue
Block a user