sse_parser v0.1.0 SseParser
Server sent event parser acording to w3c using NimbleParsec ref: https://www.w3.org/TR/2009/WD-eventsource-20090421
ABNF: stream = [ bom ] event event = ( comment / field ) end-of-line comment = colon any-char end-of-line field = 1name-char [ colon [ space ] *any-char ] end-of-line end-of-line = ( cr lf / cr / lf / eof ) eof = < matches repeatedly at the end of the stream >
; characters lf = %x000A ; U+000A LINE FEED cr = %x000D ; U+000D CARRIAGE RETURN space = %x0020 ; U+0020 SPACE colon = %x003A ; U+003A COLON bom = %xFEFF ; U+FEFF BYTE ORDER MARK name-char = %x0000-0009 / %x000B-000C / %x000E-0039 / %x003B-10FFFF
; a Unicode character other than U+000A LINE FEED, U+000D CARRIAGE RETURN, or U+003A COLON
any-char = %x0000-0009 / %x000B-000C / %x000E-10FFFF
; a Unicode character other than U+000D CARRIAGE RETURN or U+003A COLON
Link to this section Summary
Functions
Parse string to sse events, returning parsed events and unparsed part of input, unparsed part can be used when next chunk from sse arrive
Link to this section Types
comment()
Specs
comment() :: {:comment, String.t()}
error()
Specs
event()
Specs
feed_error()
Specs
feed_success()
Specs
field()
Specs
Link to this section Functions
feed(data)
Specs
feed(String.t()) :: feed_success() | feed_error()
Parse string to sse events, returning parsed events and unparsed part of input, unparsed part can be used when next chunk from sse arrive
Examples
iex> SseParser.feed(":Order 3 submitted\nevent: order-submitted\nreference: order 3\n\n")
iex> SseParser.feed(":Test event")
iex> {:ok, [], rest} = SseParser.feed(":Test event") iex> {:ok, [], rest} = SseParser.feed(rest <> "\nname: test") iex> SseParser.feed(rest <> "\n\n")