2021-12-11 22:43:41 -05:00
|
|
|
//! Subscription close request parsing
|
2022-02-12 10:29:35 -05:00
|
|
|
//!
|
|
|
|
//! Representation and parsing of `CLOSE` messages sent from clients.
|
2021-12-05 18:33:40 -05:00
|
|
|
use crate::error::{Error, Result};
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
2021-12-11 22:43:41 -05:00
|
|
|
/// Close command in network format
|
2022-09-24 09:30:22 -04:00
|
|
|
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
|
2021-12-05 19:14:14 -05:00
|
|
|
pub struct CloseCmd {
|
2021-12-11 22:43:41 -05:00
|
|
|
/// Protocol command, expected to always be "CLOSE".
|
2021-12-05 18:33:40 -05:00
|
|
|
cmd: String,
|
2021-12-11 22:43:41 -05:00
|
|
|
/// The subscription identifier being closed.
|
2021-12-05 18:33:40 -05:00
|
|
|
id: String,
|
|
|
|
}
|
|
|
|
|
2022-02-12 10:29:35 -05:00
|
|
|
/// Identifier of the subscription to be closed.
|
2022-09-24 09:30:22 -04:00
|
|
|
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
|
2021-12-05 19:14:14 -05:00
|
|
|
pub struct Close {
|
2021-12-11 22:43:41 -05:00
|
|
|
/// The subscription identifier being closed.
|
2021-12-11 16:48:59 -05:00
|
|
|
pub id: String,
|
2021-12-05 19:14:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl From<CloseCmd> for Result<Close> {
|
|
|
|
fn from(cc: CloseCmd) -> Result<Close> {
|
|
|
|
// ensure command is correct
|
2022-09-24 10:01:09 -04:00
|
|
|
if cc.cmd == "CLOSE" {
|
2021-12-11 22:56:52 -05:00
|
|
|
Ok(Close { id: cc.id })
|
2022-09-24 10:01:09 -04:00
|
|
|
} else {
|
|
|
|
Err(Error::CommandUnknownError)
|
2021-12-05 18:33:40 -05:00
|
|
|
}
|
|
|
|
}
|
2021-12-05 19:14:14 -05:00
|
|
|
}
|