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