Replies: 1 comment
-
|
Thank you for the question, @jano7 The supervisor is defined as If I understand your case properly, you translate from one protocol (UDP) to another (Tokio channels in Maiko). That's completely doable - you simply need a dedicated actor that translates UDP packets into internal events (you call them commands). It would look as such (pseudocode): pub struct UDPReceiver {
ctx: maiko::Context<Command>,
sock: UdpSocket
}
impl Actor for UDPReceiver {
async fn step(&mut self) -> maiko::Result<StepAction> {
let mut buf = [0; 1024];
let (len, addr) = self.sock.recv_from(&mut buf).await?; // read from udp
if let Ok(event) = Command::try_from((&buf, len)) { // try to convert the udp to local event (Command)
self.ctx.send(event).await; // send the command
}
Ok(StepAction::Yield) // or StepAction::Continue
}
}
#[derive(Event, Label)]
pub enum Command {
Left, Right, Up, Down
}
impl TryFrom<(&[u8], len)> for Command {
// do the conversion
}In the example the actor is pure event producer - it listens to UDP packets and sends events. It even doesn't listen to other Maiko events. If it needed to - you just add Hope that makes sense. If you want to clarify it further i am happy to help. On real life example similar (somehow) to your case - in my project Charon I have an actor that listens to Linux system events (evdev) and translates them to Maiko events. Same idea, just different protocol. See it here: KeyScanner |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
For example an actor of a drone app which is responsible for converting UDP packets (
type Event = UDP) from a receiver to a command (which is an enum of UP/DOWN/RIGHT/LEFT...).Beta Was this translation helpful? Give feedback.
All reactions