17 lines
578 B
Dart
17 lines
578 B
Dart
/// SignalR text framing (record separator 0x1E).
|
|
class TextMessageFormat {
|
|
static const int recordSeparatorCode = 0x1e;
|
|
static final String recordSeparator = String.fromCharCode(recordSeparatorCode);
|
|
|
|
static String write(String output) => '$output$recordSeparator';
|
|
|
|
static List<String> parse(String input) {
|
|
if (input.isEmpty || input.codeUnitAt(input.length - 1) != recordSeparatorCode) {
|
|
throw StateError('Message is incomplete.');
|
|
}
|
|
final List<String> messages = input.split(recordSeparator);
|
|
messages.removeLast();
|
|
return messages;
|
|
}
|
|
}
|