parseSse method

Map<String, dynamic> parseSse(
  1. String event
)

Parses a raw SSE event string into a map.

Implementation

Map<String, dynamic> parseSse(String event) {
  final List<String> splittedEvent;

  try {
    // Split SSE event lines
    splittedEvent = event.split('\n');
  } catch (e) {
    throw SseParseException(
      message: 'Failed to split SSE into lines',
      source: event,
      originalExeption: e,
    );
  }

  try {
    /// Parse each SSE line and combine into a single [Map]
    return Map.fromEntries(splittedEvent.map(parseLine));
  } on SseParseException catch (e) {
    throw SseParseException(
      message: e.message,
      originalExeption: e.originalExeption,
      source: event,
    );
  } catch (e) {
    rethrow;
  }
}