use std::net::TcpStream;
use serde::Serialize;
use serde_json::{Map, Value};
use crate::actor::{Actor, ActorMessageStatus, ActorRegistry};
use crate::protocol::JsonPacketStream;
use crate::{EmptyReplyMsg, StreamId};
#[derive(Serialize)]
pub struct NetworkParentActorMsg {
actor: String,
}
pub struct NetworkParentActor {
name: String,
}
impl Actor for NetworkParentActor {
fn name(&self) -> String {
self.name.clone()
}
fn handle_message(
&self,
_registry: &ActorRegistry,
msg_type: &str,
_msg: &Map<String, Value>,
stream: &mut TcpStream,
_id: StreamId,
) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type {
"setSaveRequestAndResponseBodies" => {
let msg = EmptyReplyMsg { from: self.name() };
let _ = stream.write_json_packet(&msg);
ActorMessageStatus::Processed
},
_ => ActorMessageStatus::Ignored,
})
}
}
impl NetworkParentActor {
pub fn new(name: String) -> Self {
Self { name }
}
pub fn encodable(&self) -> NetworkParentActorMsg {
NetworkParentActorMsg { actor: self.name() }
}
}