diff --git a/include/mqtt/properties.h b/include/mqtt/properties.h index 3a693633..c0d0f508 100644 --- a/include/mqtt/properties.h +++ b/include/mqtt/properties.h @@ -205,7 +205,7 @@ inline T get(const property&) { */ template <> inline uint8_t get(const property& prop) { - return (uint8_t)prop.c_struct().value.byte; + return uint8_t(prop.c_struct().value.byte); } /** @@ -214,7 +214,7 @@ inline uint8_t get(const property& prop) { */ template <> inline uint16_t get(const property& prop) { - return (uint16_t)prop.c_struct().value.integer2; + return uint16_t(prop.c_struct().value.integer2); } /** @@ -226,7 +226,7 @@ inline uint16_t get(const property& prop) { template <> [[deprecated("Integer properties are unsigned. Use get()")]] inline int16_t get(const property& prop) { - return (int16_t)prop.c_struct().value.integer2; + return int16_t(prop.c_struct().value.integer2); } /** @@ -235,7 +235,7 @@ get(const property& prop) { */ template <> inline uint32_t get(const property& prop) { - return (uint32_t)prop.c_struct().value.integer4; + return uint32_t(prop.c_struct().value.integer4); } /** @@ -247,7 +247,7 @@ inline uint32_t get(const property& prop) { template <> [[deprecated("Integer properties are unsigned. Use get()")]] inline int32_t get(const property& prop) { - return (int32_t)prop.c_struct().value.integer4; + return int32_t(prop.c_struct().value.integer4); } /** diff --git a/src/properties.cpp b/src/properties.cpp index 390933fe..262ea670 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -58,9 +58,11 @@ property::property(code c, int32_t val) switch (::MQTTProperty_getType(prop_.identifier)) { case MQTTPROPERTY_TYPE_BYTE: + prop_.value.integer4 = 0; prop_.value.byte = uint8_t(val); break; case MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER: + prop_.value.integer4 = 0; prop_.value.integer2 = uint16_t(val); break; case MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER: @@ -199,7 +201,13 @@ std::ostream& operator<<(std::ostream& os, const property& prop) switch (::MQTTProperty_getType(MQTTPropertyCodes(prop.type()))) { case MQTTPROPERTY_TYPE_BYTE: + os << get(prop); + break; + case MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER: + os << get(prop); + break; + case MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER: case MQTTPROPERTY_TYPE_VARIABLE_BYTE_INTEGER: os << get(prop);