asdf-overlay-common 0.1.2

Asdf Overlay Ipc messages, client and server
Documentation
use bincode::{Decode, Encode};
use tokio::io::{self, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};

use crate::message::{Request, Response};

pub mod client;
pub mod server;

/// Create Windows pipe path using unique name and pid
pub fn create_ipc_path(name: &str, pid: u32) -> String {
    format!("\\\\.\\pipe\\{name}-{pid}")
}

#[derive(Encode, Decode)]
struct ServerRequest {
    pub id: u32,
    pub req: Request,
}

#[derive(Encode, Decode)]
struct ClientResponse {
    pub id: u32,
    pub body: Response,
}

#[derive(Debug, Clone, Copy)]
struct Frame {
    size: u32,
}

impl Frame {
    async fn read(mut r: impl AsyncRead + Unpin) -> io::Result<Self> {
        Ok(Self {
            size: r.read_u32().await?,
        })
    }

    async fn write(self, mut w: impl AsyncWrite + Unpin) -> io::Result<()> {
        w.write_u32(self.size).await?;
        Ok(())
    }
}