Crates.io | clia-sse-msg-codec |
lib.rs | clia-sse-msg-codec |
version | 0.1.0 |
source | src |
created_at | 2022-03-22 06:40:19.575987 |
updated_at | 2022-03-22 06:40:19.575987 |
description | A Rust lib to encode and decode the SSE (Server-Sent Events) protocol message. |
homepage | |
repository | https://github.com/clia/sse-msg-codec |
max_upload_size | |
id | 554514 |
size | 6,302 |
A Rust lib to encode and decode the SSE (Server-Sent Events) protocol message.
The SSE (Server-Sent Events) Protocol, See: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format
Encode:
let encoded = sse_msg_codec::encode(
Some("test-id"),
Some("test-event"),
Some("test-data line1\nline2"),
);
assert_eq!(
encoded,
"id: test-id\nevent: test-event\ndata: test-data line1\ndata: line2\n\n".to_owned(),
);
Decode:
let msg = "id: test-id\nevent: test-event\ndata: test-data line1\ndata: line2\n\n";
let decoded = sse_msg_codec::decode(msg);
assert_eq!(decoded, SseMsg {
id: Some("test-id".to_owned()),
event: Some("test-event".to_owned()),
data: Some("test-data line1\nline2".to_owned()),
});