//! The decode step as the job sees it: bytes in, a classified child run out. The real //! implementation spawns this very binary as `decode` (R0 `Spawner`); tests inject outcomes. use crate::spawn::{ChildRun, Spawner}; pub trait Decoder { fn decode(&self, bytes: &[u8]) -> ChildRun; } /// Spawns `faunosteo-worker decode` from the running executable. #[derive(Debug, Clone)] pub struct ChildDecoder { spawner: Spawner, } impl ChildDecoder { /// Fails only when the executable path cannot be resolved (then nothing can be decoded). pub fn from_current_exe() -> std::io::Result { Ok(Self { spawner: Spawner::new(std::env::current_exe()?), }) } } impl Decoder for ChildDecoder { fn decode(&self, bytes: &[u8]) -> ChildRun { self.spawner.decode(bytes) } }