-
Notifications
You must be signed in to change notification settings - Fork 437
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use a enum class for QoS type #52
Conversation
I'm not convinced of this one. By close compatibility with the C library, and a convention across most of the Paho libraries, the QOS is just typed as an int. It is discussed by its integer values (0, 1, 2) in documentation and lists, and might be more confusing as an enumeration than just leaving it as an int. |
My initial idea was to improve type safety. But thinking again, a QoS enumerator name might be more confusing than a simple number. |
If you are concerned about readability, what do you think about using the numbers as enumerators? Something like this:
My idea here is to let the compiler warn if someone is using an arbitrary integer variable, or a constant, instead of a QoS value. The validation function (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this break existing applications? If yes, please do not do this.
Convert to integer only in the interface with Paho MQTT C. This ensures that QoS will be used consciously. And the user will not provide an arbitrary integer instead of a QoS value. +-----------------+ | | | Paho MQTT C++ | <-- Use only QoS enumeration | | +-----------------+ <-- Conversion between QoS enum and int | | | Paho MQTT C | <-- Deal with interger QoS | | +-----------------+ The mqtt::QoS enumerators have sizeof(int) because an array of QoS might be cast to an array of integers. Thus, each element must have the same size. Signed-off-by: Guilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
7d7a440
to
ab6f092
Compare
I think to leave the QoS as an int for v1.0. A major point of the initial release was compatibility with the other Paho libraries, so let's stick with their lead. |
Convert to integer only in the interface with Paho MQTT C. This ensures that QoS will be used consciously. And the user will not provide an arbitrary integer instead of a QoS value.
The
mqtt::QoS
enumerators havesizeof(int)
because an array of QoS might be cast to an array of integers. Thus, each element must have the same size.