parseLine static method
Parses each separated line of an SSE event.
Implementation
//TODO(nvkantonio): Rework this to properly utilize
// SSE documentation practices
static MapEntry<String, String> parseLine(String line) {
try {
final separatorIndex = line.indexOf(': ');
if (separatorIndex < 2) {
throw SseParseException(message: 'Invalid line: $line');
}
final key = line.substring(0, separatorIndex);
final value = line.substring(separatorIndex + 2, line.length);
if (key.isEmpty || value.isEmpty) {
throw SseParseException(message: 'Invalid line: $line');
}
return MapEntry<String, String>(key, value);
} on SseParseException {
rethrow;
} catch (e) {
throw SseParseException(
message: 'Failed to parse SSE line: $line',
originalException: e,
);
}
}