#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum Command {
Exec = 0x10,
Ping = 0x20,
QueryStack = 0x30,
QueryMemory = 0x40,
QueryWord = 0x50,
Reset = 0xFF,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum ErrorCode {
Ok = 0x00,
Error = 0x01,
InvalidFrame = 0x02,
BufferFull = 0x03,
VmError = 0x04,
}
impl ErrorCode {
pub fn from_u8(value: u8) -> Option<Self> {
match value {
0x00 => Some(ErrorCode::Ok),
0x01 => Some(ErrorCode::Error),
0x02 => Some(ErrorCode::InvalidFrame),
0x03 => Some(ErrorCode::BufferFull),
0x04 => Some(ErrorCode::VmError),
_ => None,
}
}
pub fn name(&self) -> &'static str {
match self {
ErrorCode::Ok => "OK",
ErrorCode::Error => "ERROR",
ErrorCode::InvalidFrame => "INVALID_FRAME",
ErrorCode::BufferFull => "BUFFER_FULL",
ErrorCode::VmError => "VM_ERROR",
}
}
}