Improved plugin loader

This commit is contained in:
2025-12-11 23:19:56 +01:00
parent 5e2e819a94
commit 4d6c69772b
3 changed files with 44 additions and 18 deletions
+22 -4
View File
@@ -1,7 +1,25 @@
use std::net::TcpStream;
pub mod loader;
pub mod types;
pub struct Plugin(TcpStream);
use std::{
io::{BufRead, BufReader, Read, Write},
net::TcpStream,
};
impl Plugin {}
use crate::plugin::types::{LoaderMessage, PluginMessage};
pub struct Plugin(TcpStream, BufReader<TcpStream>);
impl Plugin {
pub fn send(&mut self, m: LoaderMessage) {
self.0
.write(serde_json::to_string(&m).unwrap().as_bytes())
.unwrap();
}
pub fn read(&mut self) -> PluginMessage {
let mut buf = String::new();
self.1.read_line(&mut buf).unwrap();
serde_json::from_str(&buf).unwrap()
}
}