async_sse/message.rs
1/// An SSE event with a data payload.
2#[derive(Debug, PartialEq, Eq, Hash)]
3pub struct Message {
4 /// The ID of this event.
5 ///
6 /// See also the [Server-Sent Events spec](https://html.spec.whatwg.org/multipage/server-sent-events.html#concept-event-stream-last-event-id).
7 pub(crate) id: Option<String>,
8 /// The event name. Defaults to "message" if no event name is provided.
9 pub(crate) name: String,
10 /// The data for this event.
11 pub(crate) data: Vec<u8>,
12}
13
14impl Message {
15 /// Get the message id.
16 pub fn id(&self) -> &Option<String> {
17 &self.id
18 }
19
20 /// Get the message event name.
21 pub fn name(&self) -> &String {
22 &self.name
23 }
24
25 /// Access the event data.
26 pub fn data(&self) -> &[u8] {
27 &self.data
28 }
29
30 /// Convert the message into the data payload.
31 pub fn into_bytes(self) -> Vec<u8> {
32 self.data
33 }
34}