mirror of
https://github.com/dpup/meshstream.git
synced 2026-08-06 08:43:12 +02:00
Refactor message handling to use switch statement
- Replace if-else chain with cleaner switch statement - Add support for "c" format messages - Improve code structure and readability 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+7
-4
@@ -92,8 +92,9 @@ func (c *Client) messageHandler(client mqtt.Client, msg mqtt.Message) {
|
||||
return
|
||||
}
|
||||
|
||||
// For now, only handle "e" and "map" format messages
|
||||
if topicInfo.Format == "e" || topicInfo.Format == "map" {
|
||||
// Process different message formats
|
||||
switch topicInfo.Format {
|
||||
case "e", "c", "map":
|
||||
// Binary encoded protobuf message
|
||||
decodedPacket := decoder.DecodeMessage(msg.Payload(), topicInfo)
|
||||
|
||||
@@ -114,10 +115,12 @@ func (c *Client) messageHandler(client mqtt.Client, msg mqtt.Message) {
|
||||
// Channel buffer is full, log a warning and drop the message
|
||||
log.Println("Warning: Message buffer full, dropping message")
|
||||
}
|
||||
} else if topicInfo.Format == "json" {
|
||||
|
||||
case "json":
|
||||
// TODO: Add support for JSON format messages in the future
|
||||
log.Printf("Ignoring JSON format message from topic: %s\n", msg.Topic())
|
||||
} else {
|
||||
|
||||
default:
|
||||
// Unsupported format, log and ignore
|
||||
log.Printf("Unsupported format: %s from topic: %s\n", topicInfo.Format, msg.Topic())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user