marvinroger/async-mqtt-client

Make topic const

bertmelis opened this issue · 4 comments

I'd like to propose a breaking change: make the topic in the onMessage callback const.

Under the hood the topic is indeed a char* but the end user shouldn't change the contents. I don't think there's a reason to anyway, but still...

typedef std::function<void(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total)> OnMessageUserCallback;

+1 for this. I also suggest that the payload should be of type const uint8_t * instead of plain char * which is little confusing for newbies.

+1. I typically add const everywhere. And yes to using the uint8_t instead of char. Maybe worth running the code through cppcheck/clangtidy or a service like codacy to see what other minor changes we could add?

+1 for this. I also suggest that the payload should be of type const uint8_t * instead of plain char * which is little confusing for newbies.

Yes, that would also be better indeed.

+1 for both changes