Conversation
- Add empty properties in CONNECT, PUBLISH, SUBSCRIBE, UNSUBSCRIBE packets - Add will properties support in CONNECT packet for MQTT v5 - Skip v5 properties in CONNACK, PUBLISH, SUBACK, UNSUBACK responses - Add mqtt_v5_skip_properties() helper for parsing v5 property sections - Add AUTH packet type (type 15) to mqtt_type_e enum - Add setProtocolVersion() method to C++ MqttClient class - Include hmath.h for varint_decode used in property skipping Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds basic MQTT 5.0 framing compatibility to libhv’s MQTT client so it can interoperate with v5 brokers for simple CONNECT + publish/subscribe workflows by emitting empty Properties sections and skipping Properties on incoming packets.
Changes:
- Add MQTT v5 packet framing support by appending empty Properties (varint length = 0) to CONNECT (incl. Will), PUBLISH, SUBSCRIBE, and UNSUBSCRIBE outbound packets.
- Add inbound parsing support for MQTT v5 by skipping Properties on CONNACK/PUBLISH/SUBACK/UNSUBACK using a
mqtt_v5_skip_properties()helper (based onvarint_decode). - Update protocol definitions (MQTT v5 no longer marked unsupported; add
MQTT_TYPE_AUTH) and exposeMqttClient::setProtocolVersion()in the C++ wrapper.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| mqtt/mqtt_protocol.h | Updates MQTT v5 protocol constants and adds MQTT_TYPE_AUTH. |
| mqtt/mqtt_client.h | Adds C++ API to set protocol_version on the underlying C client. |
| mqtt/mqtt_client.c | Implements minimal MQTT v5 properties framing (send empty properties; skip received properties). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mqtt/mqtt_client.c
Outdated
| * 2 + protocol_name + 1 protocol_version + 1 conn_flags + 2 keepalive + | ||
| * [v5: properties] + | ||
| * 2 + [client_id] + | ||
| * [v5: 2 + will_properties] + [2 + will_topic + 2 + will_payload] + |
There was a problem hiding this comment.
The CONNECT format comment is inaccurate for MQTT v5: Will Properties are prefixed by a variable-byte integer property length (1–4 bytes), not a 2-byte length field. Consider updating the comment to avoid implying a fixed 2-byte prefix for will_properties.
| * [v5: 2 + will_properties] + [2 + will_topic + 2 + will_payload] + | |
| * [v5: varint + will_properties] + [2 + will_topic + 2 + will_payload] + |
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: ithewei <26049660+ithewei@users.noreply.github.com>
Fixed in |
mqtt/mqtt_protocol.h: Fix typo in MQTT_PROTOCOL_V5 comment, add AUTH packet type (v5)mqtt/mqtt_client.c: Add#include "hmath.h"for varint_decode, add helper to skip v5 propertiesmqtt/mqtt_client.cmqtt_client_login(): Add empty MQTT v5 properties in CONNECT packet (Variable Header properties + Will properties)mqtt/mqtt_client.con_packet(): Skip v5 properties in CONNACK, PUBLISH, SUBACK, UNSUBACK parsingmqtt/mqtt_client.cmqtt_client_publish(): Add empty v5 properties in PUBLISH packetmqtt/mqtt_client.cmqtt_client_subscribe(): Add empty v5 properties in SUBSCRIBE packetmqtt/mqtt_client.cmqtt_client_unsubscribe(): Add empty v5 properties in UNSUBSCRIBE packetmqtt/mqtt_client.h: AddsetProtocolVersion()method to C++ MqttClient classOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.