dispatcher

This commit is contained in:
2023-11-27 13:09:41 +01:00
parent 7262592576
commit a1fbdb7677
4 changed files with 62 additions and 24 deletions

View File

@ -1,6 +1,7 @@
package mqtt
import "log"
import "strings"
import "fmt"
import MQTT "github.com/eclipse/paho.mqtt.golang"
import "github.com/google/uuid"
@ -124,3 +125,20 @@ func StopMqttClient() {
mqttClient.Disconnect(250)
}
func TopicMatchesSubscription(topic, subscription string) bool {
topicSegments := strings.Split(topic, "/")
subscriptionSegments := strings.Split(subscription, "/")
for i, subSegment := range subscriptionSegments {
if subSegment == "+" {
continue
} else if subSegment == "#" {
return true
} else if i < len(topicSegments) && subSegment != topicSegments[i] {
return false
}
}
return true
}