event_stream v0.1.0 EventStream View Source
Module for encoding to and decoding from the AWS EventStream Encoding format.
https://docs.aws.amazon.com/transcribe/latest/dg/event-stream.html
Link to this section Summary
Functions
Decode a payload and headers from Event Stream format.
Encode a payload and headers to Event Stream format.
Link to this section Functions
Decode a payload and headers from Event Stream format.
Examples
iex> data = <<0, 0, 0, 30, 0, 0, 0, 0, 186, 242, 246, 138, 123, 34, 102, 111,
...> 111, 34, 58, 32, 34, 98, 97, 114, 34, 125, 174, 114, 88, 228>>
...> EventStream.decode!(data)
{:ok, [], ~s/{"foo": "bar"}/}
iex> data = <<0, 0, 0, 62, 0, 0, 0, 32, 64, 93, 249, 70, 12, 99, 111, 110, 116, 101, 110,
...> 116, 45, 116, 121, 112, 101, 7, 0, 16, 97, 112, 112, 108, 105, 99, 97, 116,
...> 105, 111, 110, 47, 106, 115, 111, 110, 123, 34, 102, 111, 111, 34, 58, 32, 34,
...> 98, 97, 114, 34, 125, 111, 162, 191, 59>>
...> EventStream.decode!(data)
{:ok, [{"content-type", "application/json"}], ~s/{"foo": "bar"}/}
Encode a payload and headers to Event Stream format.
Examples
iex> EventStream.encode!(~s/{"foo": "bar"}/)
<<0, 0, 0, 30, 0, 0, 0, 0, 186, 242, 246, 138, 123, 34, 102, 111,
111, 34, 58, 32, 34, 98, 97, 114, 34, 125, 174, 114, 88, 228>>
iex> EventStream.encode!(~s/{"foo": "bar"}/, "content-type": "application/json")
<<0, 0, 0, 62, 0, 0, 0, 32, 64, 93, 249, 70, 12, 99, 111, 110, 116, 101, 110,
116, 45, 116, 121, 112, 101, 7, 0, 16, 97, 112, 112, 108, 105, 99, 97, 116,
105, 111, 110, 47, 106, 115, 111, 110, 123, 34, 102, 111, 111, 34, 58, 32, 34,
98, 97, 114, 34, 125, 111, 162, 191, 59>>