Skip to content

Commit

Permalink
Fixed num_of_const_buffer_sequence().
Browse files Browse the repository at this point in the history
  • Loading branch information
redboltz committed Feb 6, 2024
1 parent b0d513b commit 29dedbf
Show file tree
Hide file tree
Showing 40 changed files with 211 additions and 40 deletions.
12 changes: 6 additions & 6 deletions include/async_mqtt/packet/v3_1_1_publish.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,12 +301,12 @@ class basic_publish_packet {
*/
std::size_t num_of_const_buffer_sequence() const {
return
1U + // fixed header
1U + // remaining length
2U + // topic name length, topic name
[&] {
if (packet_id() == 0) return 0U;
return 1U;
1 + // fixed header
1 + // remaining length
2 + // topic name length, topic name
[&] () -> std::size_t {
if (packet_id() == 0) return 0;
return 1;
}() +
payloads_.size();

Expand Down
2 changes: 1 addition & 1 deletion include/async_mqtt/packet/v3_1_1_suback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class basic_suback_packet {
1 + // fixed header
1 + // remaining length
1 + // packet id
entries_.size(); // suback_return_code
1; // suback_return_code vector
}

/**
Expand Down
16 changes: 11 additions & 5 deletions include/async_mqtt/packet/v5_auth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,18 @@ class auth_packet {
return
1 + // fixed header
1 + // remaining length
1 + // reason_code
[&] () -> std::size_t {
if (property_length_buf_.size() == 0) return 0;
return
1 + // property length
async_mqtt::num_of_const_buffer_sequence(props_);
if (reason_code_) {
return
1 + // reason_code
[&] () -> std::size_t {
if (property_length_buf_.size() == 0) return 0;
return
1 + // property length
async_mqtt::num_of_const_buffer_sequence(props_);
}();
}
return 0;
}();
}

Expand Down
1 change: 1 addition & 0 deletions include/async_mqtt/packet/v5_connack.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ class connack_packet {
1 + // remaining length
1 + // connect_acknowledge_flags
1 + // reason_code
1 + // property length
async_mqtt::num_of_const_buffer_sequence(props_);
}

Expand Down
16 changes: 11 additions & 5 deletions include/async_mqtt/packet/v5_disconnect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,18 @@ class disconnect_packet {
return
1 + // fixed header
1 + // remaining length
1 + // reason_code
[&] () -> std::size_t {
if (property_length_buf_.size() == 0) return 0;
return
1 + // property length
async_mqtt::num_of_const_buffer_sequence(props_);
if (reason_code_) {
return
1 + // reason_code
[&] () -> std::size_t {
if (property_length_buf_.size() == 0) return 0;
return
1 + // property length
async_mqtt::num_of_const_buffer_sequence(props_);
}();
}
return 0;
}();
}

Expand Down
16 changes: 11 additions & 5 deletions include/async_mqtt/packet/v5_puback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,18 @@ class basic_puback_packet {
1 + // fixed header
1 + // remaining length
1 + // packet_id
1 + // reason_code
[&] () -> std::size_t {
if (property_length_buf_.size() == 0) return 0;
return
1 + // property length
async_mqtt::num_of_const_buffer_sequence(props_);
if (reason_code_) {
return
1 + // reason_code
[&] () -> std::size_t {
if (property_length_buf_.size() == 0) return 0;
return
1 + // property length
async_mqtt::num_of_const_buffer_sequence(props_);
}();
}
return 0;
}();
}

Expand Down
16 changes: 11 additions & 5 deletions include/async_mqtt/packet/v5_pubcomp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,18 @@ class basic_pubcomp_packet {
1 + // fixed header
1 + // remaining length
1 + // packet_id
1 + // reason_code
[&] () -> std::size_t {
if (property_length_buf_.size() == 0) return 0;
return
1 + // property length
async_mqtt::num_of_const_buffer_sequence(props_);
if (reason_code_) {
return
1 + // reason_code
[&] () -> std::size_t {
if (property_length_buf_.size() == 0) return 0;
return
1 + // property length
async_mqtt::num_of_const_buffer_sequence(props_);
}();
}
return 0;
}();
}

Expand Down
16 changes: 11 additions & 5 deletions include/async_mqtt/packet/v5_pubrec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,18 @@ class basic_pubrec_packet {
1 + // fixed header
1 + // remaining length
1 + // packet_id
1 + // reason_code
[&] () -> std::size_t {
if (property_length_buf_.size() == 0) return 0;
return
1 + // property length
async_mqtt::num_of_const_buffer_sequence(props_);
if (reason_code_) {
return
1 + // reason_code
[&] () -> std::size_t {
if (property_length_buf_.size() == 0) return 0;
return
1 + // property length
async_mqtt::num_of_const_buffer_sequence(props_);
}();
}
return 0;
}();
}

Expand Down
16 changes: 11 additions & 5 deletions include/async_mqtt/packet/v5_pubrel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,18 @@ class basic_pubrel_packet {
1 + // fixed header
1 + // remaining length
1 + // packet_id
1 + // reason_code
[&] () -> std::size_t {
if (property_length_buf_.size() == 0) return 0;
return
1 + // property length
async_mqtt::num_of_const_buffer_sequence(props_);
if (reason_code_) {
return
1 + // reason_code
[&] () -> std::size_t {
if (property_length_buf_.size() == 0) return 0;
return
1 + // property length
async_mqtt::num_of_const_buffer_sequence(props_);
}();
}
return 0;
}();
}

Expand Down
2 changes: 1 addition & 1 deletion include/async_mqtt/packet/v5_suback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ class basic_suback_packet {
1 + // property length
async_mqtt::num_of_const_buffer_sequence(props_);
}() +
entries_.size(); // suback_reason_code
1; // suback_reason_code vector
}

/**
Expand Down
2 changes: 1 addition & 1 deletion include/async_mqtt/packet/v5_unsuback.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class basic_unsuback_packet {
1 + // property length
async_mqtt::num_of_const_buffer_sequence(props_);
}() +
entries_.size(); // unsuback_reason_code
1; // unsuback_reason_code vector
}

/**
Expand Down
4 changes: 3 additions & 1 deletion test/unit/ut_packet_v3_1_1_connack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ BOOST_AUTO_TEST_CASE(v311_connack) {

{
auto cbs = p.const_buffer_sequence();
BOOST_TEST(cbs.size() == p.num_of_const_buffer_sequence());
char expected[] {
0x20, // fixed_header
0x02, // remaining_length
0x01, // session_present
0x05, // connect_return_code
};
};
auto [b, e] = am::make_packet_range(cbs);
BOOST_TEST(std::equal(b, e, std::begin(expected)));

Expand All @@ -48,6 +49,7 @@ BOOST_AUTO_TEST_CASE(v311_connack) {
BOOST_TEST(p.code() == am::connect_return_code::not_authorized);

auto cbs2 = p.const_buffer_sequence();
BOOST_TEST(cbs.size() == p.num_of_const_buffer_sequence());
auto [b2, e2] = am::make_packet_range(cbs2);
BOOST_TEST(std::equal(b2, e2, std::begin(expected)));
}
Expand Down
2 changes: 2 additions & 0 deletions test/unit/ut_packet_v3_1_1_connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ BOOST_AUTO_TEST_CASE(v311_connect) {

{
auto cbs = p.const_buffer_sequence();
BOOST_TEST(cbs.size() == p.num_of_const_buffer_sequence());
char expected[] {
0x10, // fixed_header
0x30, // remaining_length
Expand Down Expand Up @@ -85,6 +86,7 @@ BOOST_AUTO_TEST_CASE(v311_connect) {
BOOST_TEST(*p.password() == "pass1");

auto cbs2 = p.const_buffer_sequence();
BOOST_TEST(cbs2.size() == p.num_of_const_buffer_sequence());
auto [b2, e2] = am::make_packet_range(cbs2);
BOOST_TEST(std::equal(b2, e2, std::begin(expected)));
}
Expand Down
2 changes: 2 additions & 0 deletions test/unit/ut_packet_v3_1_1_disconnect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ BOOST_AUTO_TEST_CASE(v3_1_1_disconnect) {

{
auto cbs = p.const_buffer_sequence();
BOOST_TEST(cbs.size() == p.num_of_const_buffer_sequence());
char expected[] {
char(0xe0), // fixed_header
0x00, // remaining_length
Expand All @@ -39,6 +40,7 @@ BOOST_AUTO_TEST_CASE(v3_1_1_disconnect) {
auto p = am::v3_1_1::disconnect_packet{buf};

auto cbs2 = p.const_buffer_sequence();
BOOST_TEST(cbs2.size() == p.num_of_const_buffer_sequence());
auto [b2, e2] = am::make_packet_range(cbs2);
BOOST_TEST(std::equal(b2, e2, std::begin(expected)));
}
Expand Down
2 changes: 2 additions & 0 deletions test/unit/ut_packet_v3_1_1_pingreq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ BOOST_AUTO_TEST_CASE(v311_pingreq) {

{
auto cbs = p.const_buffer_sequence();
BOOST_TEST(cbs.size() == p.num_of_const_buffer_sequence());
char expected[] {
char(0xc0), // fixed_header
0x00, // remaining_length
Expand All @@ -39,6 +40,7 @@ BOOST_AUTO_TEST_CASE(v311_pingreq) {
auto p = am::v3_1_1::pingreq_packet{buf};

auto cbs2 = p.const_buffer_sequence();
BOOST_TEST(cbs2.size() == p.num_of_const_buffer_sequence());
auto [b2, e2] = am::make_packet_range(cbs2);
BOOST_TEST(std::equal(b2, e2, std::begin(expected)));
}
Expand Down
2 changes: 2 additions & 0 deletions test/unit/ut_packet_v3_1_1_pingresp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ BOOST_AUTO_TEST_CASE(v311_pingresp) {

{
auto cbs = p.const_buffer_sequence();
BOOST_TEST(cbs.size() == p.num_of_const_buffer_sequence());
char expected[] {
char(0xd0), // fixed_header
0x00, // remaining_length
Expand All @@ -39,6 +40,7 @@ BOOST_AUTO_TEST_CASE(v311_pingresp) {
auto p = am::v3_1_1::pingresp_packet{buf};

auto cbs2 = p.const_buffer_sequence();
BOOST_TEST(cbs2.size() == p.num_of_const_buffer_sequence());
auto [b2, e2] = am::make_packet_range(cbs2);
BOOST_TEST(std::equal(b2, e2, std::begin(expected)));
}
Expand Down
4 changes: 4 additions & 0 deletions test/unit/ut_packet_v3_1_1_puback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ BOOST_AUTO_TEST_CASE(v311_puback) {

{
auto cbs = p.const_buffer_sequence();
BOOST_TEST(cbs.size() == p.num_of_const_buffer_sequence());
char expected[] {
0x40, // fixed_header
0x02, // remaining_length
Expand All @@ -45,6 +46,7 @@ BOOST_AUTO_TEST_CASE(v311_puback) {
BOOST_TEST(p.packet_id() == 0x1234);

auto cbs2 = p.const_buffer_sequence();
BOOST_TEST(cbs2.size() == p.num_of_const_buffer_sequence());
auto [b2, e2] = am::make_packet_range(cbs2);
BOOST_TEST(std::equal(b2, e2, std::begin(expected)));
}
Expand All @@ -63,6 +65,7 @@ BOOST_AUTO_TEST_CASE(v311_puback_pid4) {

{
auto cbs = p.const_buffer_sequence();
BOOST_TEST(cbs.size() == p.num_of_const_buffer_sequence());
char expected[] {
0x40, // fixed_header
0x04, // remaining_length
Expand All @@ -76,6 +79,7 @@ BOOST_AUTO_TEST_CASE(v311_puback_pid4) {
BOOST_TEST(p.packet_id() == 0x12345678);

auto cbs2 = p.const_buffer_sequence();
BOOST_TEST(cbs2.size() == p.num_of_const_buffer_sequence());
auto [b2, e2] = am::make_packet_range(cbs2);
BOOST_TEST(std::equal(b2, e2, std::begin(expected)));
}
Expand Down
4 changes: 4 additions & 0 deletions test/unit/ut_packet_v3_1_1_pubcomp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ BOOST_AUTO_TEST_CASE(v311_pubcomp) {

{
auto cbs = p.const_buffer_sequence();
BOOST_TEST(cbs.size() == p.num_of_const_buffer_sequence());
char expected[] {
0x70, // fixed_header
0x02, // remaining_length
Expand All @@ -45,6 +46,7 @@ BOOST_AUTO_TEST_CASE(v311_pubcomp) {
BOOST_TEST(p.packet_id() == 0x1234);

auto cbs2 = p.const_buffer_sequence();
BOOST_TEST(cbs2.size() == p.num_of_const_buffer_sequence());
auto [b2, e2] = am::make_packet_range(cbs2);
BOOST_TEST(std::equal(b2, e2, std::begin(expected)));
}
Expand All @@ -63,6 +65,7 @@ BOOST_AUTO_TEST_CASE(v311_pubcomp_pid4) {

{
auto cbs = p.const_buffer_sequence();
BOOST_TEST(cbs.size() == p.num_of_const_buffer_sequence());
char expected[] {
0x70, // fixed_header
0x04, // remaining_length
Expand All @@ -76,6 +79,7 @@ BOOST_AUTO_TEST_CASE(v311_pubcomp_pid4) {
BOOST_TEST(p.packet_id() == 0x12345678);

auto cbs2 = p.const_buffer_sequence();
BOOST_TEST(cbs2.size() == p.num_of_const_buffer_sequence());
auto [b2, e2] = am::make_packet_range(cbs2);
BOOST_TEST(std::equal(b2, e2, std::begin(expected)));
}
Expand Down
6 changes: 6 additions & 0 deletions test/unit/ut_packet_v3_1_1_publish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ BOOST_AUTO_TEST_CASE(v311_publish) {

{
auto cbs = p.const_buffer_sequence();
BOOST_TEST(cbs.size() == p.num_of_const_buffer_sequence());
char expected[] {
0x35, // fixed_header
0x12, // remaining_length
Expand All @@ -73,6 +74,7 @@ BOOST_AUTO_TEST_CASE(v311_publish) {
BOOST_TEST(p.opts().get_dup() == am::pub::dup::no);

auto cbs2 = p.const_buffer_sequence();
BOOST_TEST(cbs2.size() == p.num_of_const_buffer_sequence());
auto [b2, e2] = am::make_packet_range(cbs2);
BOOST_TEST(std::equal(b2, e2, std::begin(expected)));
}
Expand Down Expand Up @@ -105,6 +107,7 @@ BOOST_AUTO_TEST_CASE(v311_publish_qos0) {

{
auto cbs = p.const_buffer_sequence();
BOOST_TEST(cbs.size() == p.num_of_const_buffer_sequence());
char expected[] {
0x31, // fixed_header
0x10, // remaining_length
Expand All @@ -130,6 +133,7 @@ BOOST_AUTO_TEST_CASE(v311_publish_qos0) {
BOOST_TEST(p.opts().get_dup() == am::pub::dup::no);

auto cbs2 = p.const_buffer_sequence();
BOOST_TEST(cbs2.size() == p.num_of_const_buffer_sequence());
auto [b2, e2] = am::make_packet_range(cbs2);
BOOST_TEST(std::equal(b2, e2, std::begin(expected)));
}
Expand Down Expand Up @@ -189,6 +193,7 @@ BOOST_AUTO_TEST_CASE(v311_publish_pid4) {

{
auto cbs = p.const_buffer_sequence();
BOOST_TEST(cbs.size() == p.num_of_const_buffer_sequence());
char expected[] {
0x35, // fixed_header
0x14, // remaining_length
Expand All @@ -215,6 +220,7 @@ BOOST_AUTO_TEST_CASE(v311_publish_pid4) {
BOOST_TEST(p.opts().get_dup() == am::pub::dup::no);

auto cbs2 = p.const_buffer_sequence();
BOOST_TEST(cbs2.size() == p.num_of_const_buffer_sequence());
auto [b2, e2] = am::make_packet_range(cbs2);
BOOST_TEST(std::equal(b2, e2, std::begin(expected)));
}
Expand Down
Loading

0 comments on commit 29dedbf

Please sign in to comment.