use crate::ffi_marker::FfiMarker;
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
use travsr_core::{Edge, Node};
pub const PROTOCOL_VERSION: u32 = 1;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ParseRequest {
pub path: PathBuf,
pub vname_path: String,
pub corpus: String,
pub package: String,
pub source: Option<Vec<u8>>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct ParseResponse {
pub nodes: Vec<Node>,
pub edges: Vec<Edge>,
pub ffi_markers: Vec<FfiMarker>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct InvokeRequest {
pub root: PathBuf,
#[serde(default)]
pub corpus: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
pub struct InvokeResponse {
pub nodes: Vec<Node>,
pub edges: Vec<Edge>,
}
impl InvokeResponse {
pub fn unsupported() -> Self {
Self::default()
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HandshakeRequest {
pub daemon_protocol_version: u32,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HandshakeResponse {
pub protocol_version: u32,
pub plugin_version: String,
pub language: String,
pub extensions: Vec<String>,
pub supports_phase_b: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum PluginRequest {
Handshake(HandshakeRequest),
Parse(ParseRequest),
Invoke(InvokeRequest),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum PluginResponse {
Handshake(HandshakeResponse),
Parse(ParseResponse),
Invoke(InvokeResponse),
Error(PluginError),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PluginError {
pub file: String,
pub message: String,
}