feat: add and remove subscriptions from client requests

A hashmap of active subscriptions is maintained for each client.  REQ
and CLOSE commands will modify the subscription list.
This commit is contained in:
Greg Heartsfield
2021-12-05 18:14:14 -06:00
parent 35ceb7cb64
commit 8b4c43ae71
5 changed files with 91 additions and 27 deletions
+17 -9
View File
@@ -2,20 +2,28 @@ use crate::error::{Error, Result};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub struct Close {
pub struct CloseCmd {
cmd: String,
id: String,
}
impl Close {
pub fn parse(json: &str) -> Result<Close> {
let c: Close = serde_json::from_str(json)?; //.map_err(|e| Error::JsonParseFailed(e));
if c.cmd != "CLOSE" {
return Err(Error::CloseParseFailed);
}
return Ok(c);
}
#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)]
pub struct Close {
id: String,
}
impl From<CloseCmd> for Result<Close> {
fn from(cc: CloseCmd) -> Result<Close> {
// ensure command is correct
if cc.cmd != "CLOSE" {
return Err(Error::CommandUnknownError);
} else {
return Ok(Close { id: cc.id });
}
}
}
impl Close {
pub fn get_id(&self) -> String {
self.id.clone()
}