getBytes method
Encodes all the characters in the specified string into a sequence of bytes.
Implementation
typed.Uint8Buffer getBytes(String s) {
_validateString(s);
final stringConverted = utf8.encoder.convert(s);
if (stringConverted.length > 65535) {
throw Exception(
'MqttUtf8Encoding::toUtf8 - UTF8 string length is invalid, length is ${stringConverted.length}');
}
final stringBytes = typed.Uint8Buffer();
stringBytes.add(stringConverted.length >> 8);
stringBytes.add(stringConverted.length & 0xFF);
stringBytes.addAll(stringConverted);
return stringBytes;
}