Files
zesdex/src/ipc/conn.rs
T
asepharyana fcef85a327 Refactor IPC and DTO structures; remove unused code and streamline message handling
- Removed unused structs and methods from `response.rs`, `usage.rs`, and `client.rs`.
- Simplified `Connection` handling in `conn.rs` to only support Unix sockets.
- Updated `IpcServer` to exclusively use Unix sockets and removed TCP handling.
- Cleaned up `editlog.rs` by removing loading and recent entry methods.
- Refactored `memory.rs` to eliminate unused functions related to lesson promotion and retrospective creation.
- Enhanced `search.rs` to support multiple search providers and improved error handling.
- Updated chat view logic to simplify message display and improve user experience.
- Removed deprecated modules and constants from various files to streamline the codebase.
2026-07-11 23:45:13 +07:00

35 lines
938 B
Rust

use std::os::unix::net::UnixStream;
use anyhow::Result;
use super::frame;
pub struct Connection {
inner: UnixStream,
}
impl Connection {
pub fn from_stream(stream: UnixStream) -> Result<Self> {
Ok(Connection { inner: stream })
}
pub fn connect_unix(path: &str) -> Result<Self> {
let stream = UnixStream::connect(path)?;
Ok(Connection { inner: stream })
}
pub fn send<T: serde::Serialize>(&mut self, value: &T) -> Result<()> {
let data = frame::serialize_frame(value)?;
frame::write_frame(&mut self.inner, &data)
}
pub fn receive<T: serde::de::DeserializeOwned>(&mut self) -> Result<Option<T>> {
let data = frame::read_frame(&mut self.inner)?;
match data {
Some(bytes) => {
let value: T = frame::deserialize_frame(&bytes)?;
Ok(Some(value))
}
None => Ok(None),
}
}
}