From cbe477a701461cbbd7e518f895ad947e5e021e1e Mon Sep 17 00:00:00 2001 From: Bruno Iljazovic Date: Wed, 14 Feb 2024 13:06:43 +0100 Subject: [PATCH] Correct two/four byte integer properties' types. Reviewers: ivica Reviewed By: ivica Subscribers: korina Differential Revision: https://repo.mireo.local/D27901 --- .../reference/properties/connack_props.qbk | 8 +++--- .../reference/properties/connect_props.qbk | 8 +++--- .../reference/properties/disconnect_props.qbk | 2 +- .../reference/properties/publish_props.qbk | 8 +++--- .../reference/properties/subscribe_props.qbk | 6 ++-- doc/qbk/reference/properties/will_props.qbk | 4 +-- .../async_mqtt5/impl/codecs/base_decoders.hpp | 15 ++++------ .../async_mqtt5/impl/codecs/base_encoders.hpp | 16 +++++------ include/async_mqtt5/property_types.hpp | 16 +++++------ test/integration/async_sender.cpp | 2 +- test/unit/compilation_checks.cpp | 2 +- test/unit/serialization.cpp | 28 +++++++++---------- test/unit/session.cpp | 2 +- test/unit/subscribe_op.cpp | 2 +- 14 files changed, 57 insertions(+), 62 deletions(-) diff --git a/doc/qbk/reference/properties/connack_props.qbk b/doc/qbk/reference/properties/connack_props.qbk index 97d8567..876f191 100644 --- a/doc/qbk/reference/properties/connack_props.qbk +++ b/doc/qbk/reference/properties/connack_props.qbk @@ -7,11 +7,11 @@ This section lists all possible __CONNACK__ Properties and describes their usage [table:connack_props CONNACK properties [[Identifier] [Value type] [Description]] - [[session_expiry_interval] [`int32_t`] [Represents the Session Expiry Internal in seconds.]] - [[receive_maximum] [`int16_t`] [The maximum number of QoS 1 and QoS 2 publications that the Server is willing to process concurrently.]] + [[session_expiry_interval] [`uint32_t`] [Represents the Session Expiry Internal in seconds.]] + [[receive_maximum] [`uint16_t`] [The maximum number of QoS 1 and QoS 2 publications that the Server is willing to process concurrently.]] [[maximum_qos] [`uint8_t`] [The highest QoS the Server supports.]] [[retain_available] [`uint8_t`] [A value of 0 means that retained message are not supported. A value of 1 means they are supported.]] - [[maximum_packet_size] [`int32_t`] [The maximum __PACKET_SIZE__ in bytes as defined by the specification that the Server is willing to accept.]] + [[maximum_packet_size] [`uint32_t`] [The maximum __PACKET_SIZE__ in bytes as defined by the specification that the Server is willing to accept.]] [[assigned_client_identifier] [`std::string`] [The Client Identifier which was assigned by the Server because a zero length Client Identifier was found in the __CONNECT__ packet]] [[topic_alias_maximum] [`uint16_t`] [The highest value that the Server will accept as a Topic Alias sent by the Client.]] [[reason_string] [`std::string`] [A UTF-8 Encoded String representing the reason associated with this response.]] @@ -23,7 +23,7 @@ This section lists all possible __CONNACK__ Properties and describes their usage A value of 1 means they are supported. If not present, they are supported.]] [[shared_subscription_available] [`uint8_t`] [A value of 0 means that Shared Subscriptions are not supported. A value of 1 means they are supported. If not present, they are supported.]] - [[server_keep_alive] [`int16_t`] [The Keep Alive time assigned by the Server.]] + [[server_keep_alive] [`uint16_t`] [The Keep Alive time assigned by the Server.]] [[response_information] [`std::string`] [A UTF-8 Encoded String which is used as the basis for creating a Response Topic.]] [[server_reference] [`std::string`] [A UTF-8 Encoded String which can be used by the Client to identfy another Server to use.]] [[authentication_method] [`std::string`] [A UTF-8 Encoded String containing the name of the authentication method used for extended authentication.]] diff --git a/doc/qbk/reference/properties/connect_props.qbk b/doc/qbk/reference/properties/connect_props.qbk index 0e98334..0b4c5d0 100644 --- a/doc/qbk/reference/properties/connect_props.qbk +++ b/doc/qbk/reference/properties/connect_props.qbk @@ -7,9 +7,9 @@ This section lists all possible __CONNECT__ Properties and describes their usage [table:connect_props CONNECT properties [[Identifier] [Value type] [Description]] - [[session_expiry_interval] [`int32_t`] [Represents the Session Expiry Internal in seconds.]] - [[receive_maximum] [`int16_t`] [The maximum number of QoS 1 and QoS 2 publications that the Client is willing to process concurrently.]] - [[maximum_packet_size] [`int32_t`] [The maximum __PACKET_SIZE__ in bytes as defined by the specification that the Client is willing to process.]] + [[session_expiry_interval] [`uint32_t`] [Represents the Session Expiry Internal in seconds.]] + [[receive_maximum] [`uint16_t`] [The maximum number of QoS 1 and QoS 2 publications that the Client is willing to process concurrently.]] + [[maximum_packet_size] [`uint32_t`] [The maximum __PACKET_SIZE__ in bytes as defined by the specification that the Client is willing to process.]] [[topic_alias_maximum] [`uint16_t`] [The highest value that the Client will accept as a Topic Alias sent by the Server.]] [[request_response_information] [`uint8_t`] [The value of 0 signals that the Server MUST NOT return Response Information in __CONNACK__. If the value if 1, it MAY return it.]] [[request_problem_information] [`uint8_t`] [The value of 0 signals that the Server MAY return a Reason String or User Properties on a __CONNACK__ or __DISCONNECT__ packet, @@ -33,7 +33,7 @@ The following example shows how to set a Property value: [!c++] async_mqtt5::connect_props props; props[async_mqtt5::prop::session_expiry_interval] = 1200; - props[async_mqtt5::prop::receive_maximum] = int16_t(100); + props[async_mqtt5::prop::receive_maximum] = uint16_t(100); The following example shows how to retrieve a Property value: diff --git a/doc/qbk/reference/properties/disconnect_props.qbk b/doc/qbk/reference/properties/disconnect_props.qbk index 9c7564f..2b36a63 100644 --- a/doc/qbk/reference/properties/disconnect_props.qbk +++ b/doc/qbk/reference/properties/disconnect_props.qbk @@ -7,7 +7,7 @@ This section lists all possible __DISCONNECT__ Properties and describes their us [table:disconnect_props DISCONNECT properties [[Identifier] [Value type] [Description]] - [[session_expiry_interval] [`int32_t`] [Represents the Session Expiry Internal in seconds. Can only be sent by the Client.]] + [[session_expiry_interval] [`uint32_t`] [Represents the Session Expiry Internal in seconds. Can only be sent by the Client.]] [[reason_string] [`std::string`] [A UTF-8 Encoded String representing the reason associated with this response.]] [[user_property] [`std::vector`] [A list of name, value pairs (__UTF8_STRING_PAIR__) defining User Properties. This property may be used to provide additional diagnostic or other information. ]] diff --git a/doc/qbk/reference/properties/publish_props.qbk b/doc/qbk/reference/properties/publish_props.qbk index 74f9fa2..ae19750 100644 --- a/doc/qbk/reference/properties/publish_props.qbk +++ b/doc/qbk/reference/properties/publish_props.qbk @@ -8,13 +8,13 @@ This section lists all possible __PUBLISH__ Properties and describes their usage [table:publish_props PUBLISH properties [[Identifier] [Value type] [Description]] [[payload_format_indicator] [`uint8_t`] [Value of 0 indicates that the Payload is in unspecified bytes. Value of 1 indicates that the Payload is UTF-8 Encoded Character Data.]] - [[message_expiry_interval] [`int32_t`] [The lifetime of the Application Message in seconds.]] - [[topic_alias] [`int16_t`] [Two Byte integer representing the Topic Alias, an integer value that is used to identify the Topic instead of using the Topic Name.]] + [[message_expiry_interval] [`uint32_t`] [The lifetime of the Application Message in seconds.]] + [[topic_alias] [`uint16_t`] [Two Byte integer representing the Topic Alias, an integer value that is used to identify the Topic instead of using the Topic Name.]] [[response_topic] [`std::string`] [A UTF-8 Encoded String which is used as the Topic Name for a response message.]] [[correlation_data] [`std::string`] [Binary Data used by the sender of the Request Message to identify which request the Response Message is for when it is received.]] [[user_property] [`std::vector`] [A list of name, value pairs (__UTF8_STRING_PAIR__) defining User Properties. The meaning of these properties is not defined by the specification.]] - [[subscription_identifier] [`uint32_t`] [Identifier of the Subscription in range of 1 to 268,435,455.]] + [[subscription_identifier] [`int32_t`] [Identifier of the Subscription in range of 1 to 268,435,455.]] [[content_type] [`std::string`] [A UTF-8 Encoded String describing the content of the Application Message.]] ] @@ -39,7 +39,7 @@ The following example shows how to retrieve a Property value: except for `async_mqtt5::prop::user_property`, where it will return an instance of its value type, `std::vector`.] [!c++] - std::optional topic_alias = props[async_mqtt5::prop::topic_alias]; + std::optional topic_alias = props[async_mqtt5::prop::topic_alias]; if (topic_alias.has_value()) // topic alias property was previously set else diff --git a/doc/qbk/reference/properties/subscribe_props.qbk b/doc/qbk/reference/properties/subscribe_props.qbk index cf17a3b..fd00286 100644 --- a/doc/qbk/reference/properties/subscribe_props.qbk +++ b/doc/qbk/reference/properties/subscribe_props.qbk @@ -7,7 +7,7 @@ This section lists all possible __SUBSCRIBE__ Properties and describes their usa [table:subscribe_props SUBSCRIBE properties [[Identifier] [Value type] [Description]] - [[subscription_identifier] [`uint32_t`] [Identifier of the Subscription in range of 1 to 268,435,455.]] + [[subscription_identifier] [`int32_t`] [Identifier of the Subscription in range of 1 to 268,435,455.]] [[user_property] [`std::vector`] [A list of name, value pairs (__UTF8_STRING_PAIR__) defining User Properties. This property can be used to send subscription related properties from the Client to the Server. The meaning of these properties is not defined by the specification ]] @@ -24,7 +24,7 @@ The following example shows how to set a Property value: [!c++] async_mqtt5::subscribe_props props; - props[async_mqtt5::prop::subscription_identifier] = 1234u; + props[async_mqtt5::prop::subscription_identifier] = 1234; The following example shows how to retrieve a Property value: @@ -32,7 +32,7 @@ The following example shows how to retrieve a Property value: except for `async_mqtt5::prop::user_property`, where it will return an instance of its value type, `std::vector`.] [!c++] - std::optional sub_id = props[async_mqtt5::prop::subscription_identifier]; + std::optional sub_id = props[async_mqtt5::prop::subscription_identifier]; if (sub_id.has_value()) // subscription identifier property was previously set else diff --git a/doc/qbk/reference/properties/will_props.qbk b/doc/qbk/reference/properties/will_props.qbk index de1102e..b71ea05 100644 --- a/doc/qbk/reference/properties/will_props.qbk +++ b/doc/qbk/reference/properties/will_props.qbk @@ -8,9 +8,9 @@ This section lists all possible [reflink2 will Will] Properties and describes th [table:will_props Will properties [[Identifier] [Value type] [Description]] - [[will_delay_interval] [`int32_t`] [The delay in seconds that need to pass before Server publishes the Client's Will Message.]] + [[will_delay_interval] [`uint32_t`] [The delay in seconds that need to pass before Server publishes the Client's Will Message.]] [[payload_format_indicator] [`uint8_t`] [Value of 0 indicates that the Will Message is in unspecified bytes. Value of 1 indicates that the Will Message is UTF-8 Encoded Character Data.]] - [[message_expiry_interval] [`int32_t`] [The lifetime of the Will Message in seconds. It is send as Publication Expiry Interval when it is published.]] + [[message_expiry_interval] [`uint32_t`] [The lifetime of the Will Message in seconds. It is send as Publication Expiry Interval when it is published.]] [[content_type] [`std::string`] [A UTF-8 Encoded String describing the content of the Will Message.]] [[response_topic] [`std::string`] [A UTF-8 Encoded String which is used as the Topic Name for a response message.]] [[correlation_data] [`std::string`] [Binary Data used by the sender of the Request Message to identify which request the Response Message is for when it is received.]] diff --git a/include/async_mqtt5/impl/codecs/base_decoders.hpp b/include/async_mqtt5/impl/codecs/base_decoders.hpp index 4a74116..76b6f3a 100644 --- a/include/async_mqtt5/impl/codecs/base_decoders.hpp +++ b/include/async_mqtt5/impl/codecs/base_decoders.hpp @@ -210,7 +210,7 @@ struct verbatim_parser : x3::parser { constexpr auto verbatim_ = verbatim_parser{}; struct varint_parser : x3::parser { - using attribute_type = uint32_t; + using attribute_type = int32_t; static bool const has_attribute = true; template @@ -225,7 +225,7 @@ struct varint_parser : x3::parser { if (iter == last) return false; - uint32_t result = 0; unsigned bit_shift = 0; + int32_t result = 0; unsigned bit_shift = 0; for (; iter != last && bit_shift < sizeof(int32_t) * 7; ++iter) { auto val = *iter; @@ -361,11 +361,6 @@ bool parse_to_prop( rv = x3::byte_.parse(iter, last, ctx, rctx, attr); prop = attr; } - if constexpr (std::is_same_v) { - int16_t attr; - rv = x3::big_word.parse(iter, last, ctx, rctx, attr); - prop = attr; - } if constexpr (std::is_same_v) { uint16_t attr; rv = x3::big_word.parse(iter, last, ctx, rctx, attr); @@ -373,12 +368,12 @@ bool parse_to_prop( } if constexpr (std::is_same_v) { int32_t attr; - rv = x3::big_dword.parse(iter, last, ctx, rctx, attr); + rv = basic::varint_.parse(iter, last, ctx, rctx, attr); prop = attr; } if constexpr (std::is_same_v) { uint32_t attr; - rv = basic::varint_.parse(iter, last, ctx, rctx, attr); + rv = x3::big_dword.parse(iter, last, ctx, rctx, attr); prop = attr; } if constexpr (std::is_same_v) { @@ -420,7 +415,7 @@ public: if (iter == last) return true; - uint32_t props_length; + int32_t props_length; if (!basic::varint_.parse(iter, last, ctx, rctx, props_length)) return false; diff --git a/include/async_mqtt5/impl/codecs/base_encoders.hpp b/include/async_mqtt5/impl/codecs/base_encoders.hpp index cba2811..c9b710b 100644 --- a/include/async_mqtt5/impl/codecs/base_encoders.hpp +++ b/include/async_mqtt5/impl/codecs/base_encoders.hpp @@ -366,29 +366,29 @@ struct prop_encoder_type { using encoder_types = std::tuple< prop_encoder_type>, prop_encoder_type>, - prop_encoder_type>, + prop_encoder_type>, prop_encoder_type, prop_encoder_type, prop_encoder_type, prop_encoder_type>, - prop_encoder_type>, + prop_encoder_type>, prop_encoder_type, - prop_encoder_type>, + prop_encoder_type>, prop_encoder_type, prop_encoder_type, prop_encoder_type>, - prop_encoder_type>, + prop_encoder_type>, prop_encoder_type>, prop_encoder_type, prop_encoder_type, prop_encoder_type, - prop_encoder_type>, - prop_encoder_type>, - prop_encoder_type>, + prop_encoder_type>, + prop_encoder_type>, + prop_encoder_type>, prop_encoder_type>, prop_encoder_type>, prop_encoder_type, - prop_encoder_type>, + prop_encoder_type>, prop_encoder_type>, prop_encoder_type> >; diff --git a/include/async_mqtt5/property_types.hpp b/include/async_mqtt5/property_types.hpp index 5d1e213..67df428 100644 --- a/include/async_mqtt5/property_types.hpp +++ b/include/async_mqtt5/property_types.hpp @@ -51,29 +51,29 @@ struct property_traits { \ constexpr std::integral_constant Pname {}; DEF_PROPERTY_TRAIT(payload_format_indicator, std::optional); -DEF_PROPERTY_TRAIT(message_expiry_interval, std::optional); +DEF_PROPERTY_TRAIT(message_expiry_interval, std::optional); DEF_PROPERTY_TRAIT(content_type, std::optional); DEF_PROPERTY_TRAIT(response_topic, std::optional); DEF_PROPERTY_TRAIT(correlation_data, std::optional); -DEF_PROPERTY_TRAIT(subscription_identifier, std::optional); -DEF_PROPERTY_TRAIT(session_expiry_interval, std::optional); +DEF_PROPERTY_TRAIT(subscription_identifier, std::optional); +DEF_PROPERTY_TRAIT(session_expiry_interval, std::optional); DEF_PROPERTY_TRAIT(assigned_client_identifier, std::optional); -DEF_PROPERTY_TRAIT(server_keep_alive, std::optional); +DEF_PROPERTY_TRAIT(server_keep_alive, std::optional); DEF_PROPERTY_TRAIT(authentication_method, std::optional); DEF_PROPERTY_TRAIT(authentication_data, std::optional); DEF_PROPERTY_TRAIT(request_problem_information, std::optional); -DEF_PROPERTY_TRAIT(will_delay_interval, std::optional); +DEF_PROPERTY_TRAIT(will_delay_interval, std::optional); DEF_PROPERTY_TRAIT(request_response_information, std::optional); DEF_PROPERTY_TRAIT(response_information, std::optional); DEF_PROPERTY_TRAIT(server_reference, std::optional); DEF_PROPERTY_TRAIT(reason_string, std::optional); -DEF_PROPERTY_TRAIT(receive_maximum, std::optional); +DEF_PROPERTY_TRAIT(receive_maximum, std::optional); DEF_PROPERTY_TRAIT(topic_alias_maximum, std::optional); -DEF_PROPERTY_TRAIT(topic_alias, std::optional); +DEF_PROPERTY_TRAIT(topic_alias, std::optional); DEF_PROPERTY_TRAIT(maximum_qos, std::optional); DEF_PROPERTY_TRAIT(retain_available, std::optional); DEF_PROPERTY_TRAIT(user_property, std::vector); -DEF_PROPERTY_TRAIT(maximum_packet_size, std::optional); +DEF_PROPERTY_TRAIT(maximum_packet_size, std::optional); DEF_PROPERTY_TRAIT(wildcard_subscription_available, std::optional); DEF_PROPERTY_TRAIT(subscription_identifier_available, std::optional); DEF_PROPERTY_TRAIT(shared_subscription_available, std::optional); diff --git a/test/integration/async_sender.cpp b/test/integration/async_sender.cpp index 7b72130..1888564 100644 --- a/test/integration/async_sender.cpp +++ b/test/integration/async_sender.cpp @@ -117,7 +117,7 @@ BOOST_FIXTURE_TEST_CASE(throttling, shared_test_data) { int handlers_called = 0; connack_props props; - props[prop::receive_maximum] = int16_t(1); + props[prop::receive_maximum] = uint16_t(1); //packets auto connack_rm = encoders::encode_connack( diff --git a/test/unit/compilation_checks.cpp b/test/unit/compilation_checks.cpp index 794dfc8..42ea8ba 100644 --- a/test/unit/compilation_checks.cpp +++ b/test/unit/compilation_checks.cpp @@ -110,7 +110,7 @@ BOOST_AUTO_TEST_CASE(client_functions) { tcp_client.connect_properties(std::move(co_props)); tcp_client.connect_property(prop::session_expiry_interval, 40); - tcp_client.connect_property(prop::receive_maximum, int16_t(10123)); + tcp_client.connect_property(prop::receive_maximum, uint16_t(10123)); tcp_client.connect_property(prop::maximum_packet_size, 103); tcp_client.connect_property(prop::topic_alias_maximum, uint16_t(12345)); tcp_client.connect_property(prop::request_response_information, uint8_t(1)); diff --git a/test/unit/serialization.cpp b/test/unit/serialization.cpp index 48fd335..ea9940a 100644 --- a/test/unit/serialization.cpp +++ b/test/unit/serialization.cpp @@ -20,9 +20,9 @@ BOOST_AUTO_TEST_CASE(test_connect) { uint16_t keep_alive = 60; bool clean_start = true; // connect properties - int32_t session_expiry_interval = 29; - int16_t receive_max = 100; - int32_t maximum_packet_size = 20000; + uint32_t session_expiry_interval = 29; + uint16_t receive_max = 100; + uint32_t maximum_packet_size = 20000; uint16_t topic_alias_max = 1200; uint8_t request_response_information = 1; uint8_t request_problem_information = 0; @@ -34,9 +34,9 @@ BOOST_AUTO_TEST_CASE(test_connect) { std::string will_topic = "will_topic"; std::string will_message = "will_message"; // will properties - int32_t will_delay_interval = 200; + uint32_t will_delay_interval = 200; uint8_t will_payload_format_indicator = 0; - int32_t will_message_expiry_interval = 2000; + uint32_t will_message_expiry_interval = 2000; std::string_view will_content_type = "will content type"; std::string_view will_response_topic = "response_topic"; std::string_view will_correlation_data = "correlation data"; @@ -124,11 +124,11 @@ BOOST_AUTO_TEST_CASE(test_connack) { uint8_t session_present = 1; uint8_t reason_code = reason_codes::server_busy.value(); - int32_t session_expiry_interval = 20; - int16_t receive_maximum = 2000; + uint32_t session_expiry_interval = 20; + uint16_t receive_maximum = 2000; uint8_t max_qos = 2; uint8_t retain_available = 0; - int32_t maximum_packet_sz = 1024; + uint32_t maximum_packet_sz = 1024; std::string assigned_client_id = "client_id"; uint16_t topic_alias_max = 128; std::string reason_string = "some reason string"; @@ -137,7 +137,7 @@ BOOST_AUTO_TEST_CASE(test_connack) { uint8_t wildcard_sub = 1; uint8_t sub_id = 1; uint8_t shared_sub = 0; - int16_t server_keep_alive = 25; + uint16_t server_keep_alive = 25; std::string response_information = "info"; std::string server_reference = "srv"; std::string authentication_method = "method"; @@ -206,13 +206,13 @@ BOOST_AUTO_TEST_CASE(test_publish) { std::string_view payload = "This is some payload I am publishing!"; uint8_t payload_format_indicator = 1; - int32_t message_expiry_interval = 70; - int16_t topic_alias = 16; + uint32_t message_expiry_interval = 70; + uint16_t topic_alias = 16; std::string response_topic = "topic/response"; std::string correlation_data = "correlation data"; std::string publish_prop_1 = "key"; std::string publish_prop_2 = "val"; - uint32_t subscription_identifier = 123456; + int32_t subscription_identifier = 123456; std::string content_type = "application/octet-stream"; publish_props pprops; @@ -436,7 +436,7 @@ BOOST_AUTO_TEST_CASE(test_pubcomp) { BOOST_AUTO_TEST_CASE(test_subscribe) { //testing variables - uint32_t sub_id = 1'234'567; + int32_t sub_id = 1'234'567; std::string user_property_1 = "SUBSCRIBE user prop"; std::string user_property_2 = "SUBSCRIBE user prop val"; @@ -601,7 +601,7 @@ BOOST_AUTO_TEST_CASE(test_disconnect) { // testing variables uint8_t reason_code = 0x04; - int32_t session_expiry_interval = 50; + uint32_t session_expiry_interval = 50; std::string reason_string = "a reason"; std::string user_property_1 = "DISCONNECT user prop"; std::string user_property_2 = "DISCONNECT user prop val"; diff --git a/test/unit/session.cpp b/test/unit/session.cpp index 1789b89..6e13d5a 100644 --- a/test/unit/session.cpp +++ b/test/unit/session.cpp @@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE(clear_waiting_on_pubrel) { svc_ptr->open_stream(); decoders::publish_message pub_msg = std::make_tuple( - "topic", int16_t(1), uint8_t(0b0100), publish_props {}, "payload" + "topic", uint16_t(1), uint8_t(0b0100), publish_props {}, "payload" ); detail::publish_rec_op { svc_ptr }.perform(pub_msg); diff --git a/test/unit/subscribe_op.cpp b/test/unit/subscribe_op.cpp index ca007b3..8ea76fb 100644 --- a/test/unit/subscribe_op.cpp +++ b/test/unit/subscribe_op.cpp @@ -164,7 +164,7 @@ BOOST_AUTO_TEST_CASE(large_subscription_id) { cprops[prop::subscription_identifier_available] = uint8_t(1); subscribe_props sprops; - sprops[prop::subscription_identifier] = std::numeric_limits::max(); + sprops[prop::subscription_identifier] = std::numeric_limits::max(); run_test(client::error::malformed_packet, "topic", sprops, cprops); }