buildAlpnExtensionData function
Implementation
Uint8List buildAlpnExtensionData(List<String> protocols) {
final listBody = BytesBuilder();
for (final proto in protocols) {
final bytes = Uint8List.fromList(utf8.encode(proto));
if (bytes.isEmpty || bytes.length > 255) {
throw ArgumentError('Invalid ALPN protocol length for "$proto"');
}
listBody.addByte(bytes.length);
listBody.add(bytes);
}
final listBytes = listBody.toBytes();
return Uint8List.fromList([
(listBytes.length >> 8) & 0xFF,
listBytes.length & 0xFF,
...listBytes,
]);
}