Add MagpieClient::send_json_message()
This commit is contained in:
parent
ea1631d24d
commit
8c8d89b34d
|
@ -3,7 +3,8 @@ pub use magpie_types;
|
||||||
use std::os::unix::net::UnixStream;
|
use std::os::unix::net::UnixStream;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use magpie_types::ClientMessenger;
|
use magpie_types::{serde::Serialize, serde_json};
|
||||||
|
use magpie_types::{ClientMessenger, MagpieServerMsg, PanelId, SendMessage};
|
||||||
|
|
||||||
/// The name of the Magpie server socket.
|
/// The name of the Magpie server socket.
|
||||||
pub const MAGPIE_SOCK: &str = "magpie.sock";
|
pub const MAGPIE_SOCK: &str = "magpie.sock";
|
||||||
|
@ -23,4 +24,10 @@ impl MagpieClient {
|
||||||
messenger: ClientMessenger::new(socket),
|
messenger: ClientMessenger::new(socket),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn send_json_message<T: Serialize>(&mut self, id: PanelId, msg: &T) {
|
||||||
|
let msg = serde_json::to_vec(msg).unwrap();
|
||||||
|
let msg = SendMessage { id, msg };
|
||||||
|
let _ = self.messenger.send(&MagpieServerMsg::SendMessage(msg));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,9 @@ use std::path::PathBuf;
|
||||||
|
|
||||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||||
|
|
||||||
|
pub use serde;
|
||||||
|
pub use serde_json;
|
||||||
|
|
||||||
/// An identifier for a Magpie panel.
|
/// An identifier for a Magpie panel.
|
||||||
///
|
///
|
||||||
/// Only valid on a connection between a single client and its server. Clients
|
/// Only valid on a connection between a single client and its server. Clients
|
||||||
|
|
Loading…
Reference in New Issue