feat: expand vehicle data platform capabilities
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
// Package vehicleprotocol owns the canonical protocol identifiers shared by
|
||||
// the vehicle data platform, statistics services and the open platform API.
|
||||
package vehicleprotocol
|
||||
|
||||
import "strings"
|
||||
|
||||
const (
|
||||
GB32960 = "GB32960"
|
||||
YutongMQTT = "YUTONG_MQTT"
|
||||
JT808 = "JT808"
|
||||
)
|
||||
|
||||
// All returns a copy so callers cannot mutate the platform-wide catalog.
|
||||
func All() []string {
|
||||
return []string{GB32960, JT808, YutongMQTT}
|
||||
}
|
||||
|
||||
// MileagePriority is the source-selection order for total mileage.
|
||||
func MileagePriority() []string {
|
||||
return []string{GB32960, YutongMQTT, JT808}
|
||||
}
|
||||
|
||||
// Canonical accepts only the identifiers persisted by ingestion and
|
||||
// statistics. Public aliases are deliberately rejected to avoid a second
|
||||
// protocol vocabulary at the API boundary.
|
||||
func Canonical(value string) (string, bool) {
|
||||
value = strings.TrimSpace(value)
|
||||
switch value {
|
||||
case GB32960, YutongMQTT, JT808:
|
||||
return value, true
|
||||
default:
|
||||
return "", false
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package vehicleprotocol
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestCanonicalCatalogIsUniqueAndRejectsAliases(t *testing.T) {
|
||||
seen := map[string]bool{}
|
||||
for _, value := range All() {
|
||||
if seen[value] {
|
||||
t.Fatalf("duplicate protocol %q", value)
|
||||
}
|
||||
seen[value] = true
|
||||
if canonical, ok := Canonical(value); !ok || canonical != value {
|
||||
t.Fatalf("canonical(%q) = %q, %v", value, canonical, ok)
|
||||
}
|
||||
}
|
||||
for _, alias := range []string{"32960", "mqtt", "808"} {
|
||||
if canonical, ok := Canonical(alias); ok {
|
||||
t.Fatalf("alias %q unexpectedly maps to %q", alias, canonical)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user