use bytes::Bytes;
use serde::{Deserialize, Serialize};
use crate::abi::{EntityId, InstanceId, Principal, RouteId, Tick, TypeCode};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[non_exhaustive]
pub enum Op {
SpawnEntity {
id: EntityId,
owner: Principal,
},
DespawnEntity {
id: EntityId,
},
SetComponent {
entity: EntityId,
type_code: TypeCode,
bytes: Bytes,
size: u64,
},
RemoveComponent {
entity: EntityId,
type_code: TypeCode,
size: u64,
},
EmitEvent {
actor: Option<EntityId>,
event_type_code: TypeCode,
event_bytes: Bytes,
},
ScheduleAction {
at: Tick,
actor: Option<EntityId>,
action_type_code: TypeCode,
action_bytes: Bytes,
action_principal: Principal,
},
SendSignal {
target: InstanceId,
route: RouteId,
payload: Bytes,
},
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn op_variants_clone() {
let id = EntityId::new(1).unwrap();
let _ = Op::SpawnEntity {
id,
owner: Principal::System,
}
.clone();
let _ = Op::DespawnEntity { id }.clone();
let _ = Op::SetComponent {
entity: id,
type_code: TypeCode(1),
bytes: Bytes::from_static(b"x"),
size: 1,
}
.clone();
let _ = Op::RemoveComponent {
entity: id,
type_code: TypeCode(1),
size: 1,
}
.clone();
let _ = Op::EmitEvent {
actor: Some(id),
event_type_code: TypeCode(2),
event_bytes: Bytes::new(),
}
.clone();
let _ = Op::ScheduleAction {
at: Tick(0),
actor: None,
action_type_code: TypeCode(3),
action_bytes: Bytes::new(),
action_principal: Principal::System,
}
.clone();
let _ = Op::SendSignal {
target: InstanceId::new(1).unwrap(),
route: RouteId(1),
payload: Bytes::new(),
}
.clone();
}
}