Skip to content

Commit

Permalink
Fixed display of 8, 16-bit properties
Browse files Browse the repository at this point in the history
  • Loading branch information
fpagliughi committed Jul 3, 2024
1 parent 134e40d commit 28477ca
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 5 additions & 5 deletions include/mqtt/properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ inline T get(const property&) {
*/
template <>
inline uint8_t get<uint8_t>(const property& prop) {
return (uint8_t)prop.c_struct().value.byte;
return uint8_t(prop.c_struct().value.byte);
}

/**
Expand All @@ -214,7 +214,7 @@ inline uint8_t get<uint8_t>(const property& prop) {
*/
template <>
inline uint16_t get<uint16_t>(const property& prop) {
return (uint16_t)prop.c_struct().value.integer2;
return uint16_t(prop.c_struct().value.integer2);
}

/**
Expand All @@ -226,7 +226,7 @@ inline uint16_t get<uint16_t>(const property& prop) {
template <>
[[deprecated("Integer properties are unsigned. Use get<uint16_t>()")]] inline int16_t
get<int16_t>(const property& prop) {
return (int16_t)prop.c_struct().value.integer2;
return int16_t(prop.c_struct().value.integer2);
}

/**
Expand All @@ -235,7 +235,7 @@ get<int16_t>(const property& prop) {
*/
template <>
inline uint32_t get<uint32_t>(const property& prop) {
return (uint32_t)prop.c_struct().value.integer4;
return uint32_t(prop.c_struct().value.integer4);
}

/**
Expand All @@ -247,7 +247,7 @@ inline uint32_t get<uint32_t>(const property& prop) {
template <>
[[deprecated("Integer properties are unsigned. Use get<uint32_t>()")]] inline int32_t
get<int32_t>(const property& prop) {
return (int32_t)prop.c_struct().value.integer4;
return int32_t(prop.c_struct().value.integer4);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions src/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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<uint8_t>(prop);
break;

case MQTTPROPERTY_TYPE_TWO_BYTE_INTEGER:
os << get<uint16_t>(prop);
break;

case MQTTPROPERTY_TYPE_FOUR_BYTE_INTEGER:
case MQTTPROPERTY_TYPE_VARIABLE_BYTE_INTEGER:
os << get<uint32_t>(prop);
Expand Down

0 comments on commit 28477ca

Please sign in to comment.