Electromosaw
Electromosaw

Reputation: 59

efficient way to encode a number in UTF - 8 - MQTT

A little conceptual question here, I have several devices (UC), each one whit a unique numeric ID, all those devices will send data trough MQTT, whit topics such as

IDx/data/etc

Where IDx would be the numeric identifier of the device, I have a few question about this setup, the topic in MQTT is encoded in UTF-8, my question is: ¿what is the efficient way to encode this number so it use the fewer number of ASCII characters? I was thinking in using base 64, but I'm not sure if exist a smartest way to encode this number so it use fewer digits

Additional information

Upvotes: 0

Views: 497

Answers (1)

hardillb
hardillb

Reputation: 59751

Assuming you can use MQTT v5 (and your client library supports it) then you don't need to worry about this at all, you can just use topic aliases.

The broker and the client work out pre-determined (as part of the first publish iirc or at subscribe time) numerical identifiers for the topics so the mapping is only sent once and then for all subsequent messages replaced by the id.

See this article for more details.

https://www.hivemq.com/blog/mqtt5-essentials-part10-topic-alias/

Upvotes: 1

Related Questions