mqtt_protocol_core/mqtt/connection/
version.rs

1// MIT License
2//
3// Copyright (c) 2025 Takatoshi Kondo
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22
23/// MQTT protocol version enumeration
24///
25/// Represents the supported MQTT protocol versions. Each variant corresponds
26/// to the protocol level value as defined in the MQTT specification.
27/// This is used throughout the library to handle version-specific behavior
28/// and feature availability.
29///
30/// # Protocol Level Values
31///
32/// The numeric values correspond to the Protocol Level field in the CONNECT packet:
33/// - v3.1.1 uses protocol level 4
34/// - v5.0 uses protocol level 5
35/// - `Undetermined` is used by servers to accept any supported version
36///
37/// # Examples
38///
39/// ```ignore
40/// use mqtt_protocol_core::mqtt::version::Version;
41///
42/// // Client specifies a specific version
43/// let client_version = Version::V5_0;
44///
45/// // Server accepts any supported version
46/// let server_version = Version::Undetermined;
47///
48/// match server_version {
49///     Version::V3_1_1 => println!("Using MQTT v3.1.1"),
50///     Version::V5_0 => println!("Using MQTT v5.0"),
51///     Version::Undetermined => println!("Waiting for client CONNECT to determine version"),
52/// }
53/// ```
54#[derive(PartialEq, Clone, Copy, Debug)]
55pub enum Version {
56    /// Version to be determined by incoming CONNECT packet
57    ///
58    /// Used by MQTT servers to indicate that the protocol version should be
59    /// determined based on the protocol level in the incoming CONNECT packet
60    /// from the client. The server will accept either v3.1.1 or v5.0 connections
61    /// and adapt accordingly. Not a valid protocol level value itself.
62    Undetermined = 0,
63
64    /// MQTT version 3.1.1 (protocol level 4)
65    ///
66    /// The widely adopted MQTT v3.1.1 specification. This version provides
67    /// the core MQTT functionality including QoS levels, retained messages,
68    /// last will and testament, and persistent sessions.
69    V3_1_1 = 4,
70
71    /// MQTT version 5.0 (protocol level 5)
72    ///
73    /// The latest MQTT specification with enhanced features including:
74    /// - User properties and reason codes
75    /// - Topic aliases and subscription identifiers  
76    /// - Message expiry and session expiry intervals
77    /// - Enhanced authentication (AUTH packets)
78    /// - Improved error handling and flow control
79    V5_0 = 5,
80}