1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright (c) 2021 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
// Use of this source is governed by Apache-2.0 License that can be found
// in the LICENSE file.
use ;
use fmt;
use Write;
use crate::;
/// Text fields within the MQTT Control Packets described later are encoded as UTF-8 strings.
/// UTF-8 [RFC3629] is an efficient encoding of Unicode [Unicode] characters that
/// optimizes the encoding of ASCII characters in support of text-based communications.
///
/// String Data is represented by a Two Byte Integer length which indicates
/// the number of data bytes, followed by characters.
///
/// Thus, the length of String Data is limited to the range of 0 to 65,535 Bytes.
///
/// ```text
/// +-------------------+
/// | String Length |
/// | |
/// +-------------------+
/// | String |
/// | |
/// +-------------------+
/// ```
///
/// The character data in a UTF-8 Encoded String MUST be well-formed UTF-8 as defined
/// by the Unicode specification [Unicode] and restated in RFC 3629 [RFC3629].
/// In particular, the character data MUST NOT include encodings of code points
/// between U+D800 and U+DFFF [MQTT-1.5.4-1].
///
/// If the Client or Server receives an MQTT Control Packet containing ill-formed UTF-8
/// it is a Malformed Packet.
///
/// A UTF-8 Encoded String MUST NOT include an encoding of the null character U+0000. [MQTT-1.5.4-2].
///
/// If a receiver (Server or Client) receives an MQTT Control Packet containing U+0000
/// it is a Malformed Packet.
///
/// The data SHOULD NOT include encodings of the Unicode [Unicode] code points listed below.
/// If a receiver (Server or Client) receives an MQTT Control Packet containing any of them
/// it MAY treat it as a Malformed Packet. These are the Disallowed Unicode code points.
///
/// - U+0001..U+001F control characters
/// - U+007F..U+009F control characters
/// - Code points defined in the Unicode specification [Unicode] to be non-characters (for example U+0FFFF)
///
/// A UTF-8 encoded sequence 0xEF 0xBB 0xBF is always interpreted as U+FEFF ("ZERO WIDTH NO-BREAK SPACE")
/// wherever it appears in a string and MUST NOT be skipped over or stripped off
/// by a packet receiver [MQTT-1.5.4-3].
///
/// [RFC3629]: https://datatracker.ietf.org/doc/html/rfc3629
/// [Unicode]: https://unicode.org/standard/standard.html
;