Unifying improv packet names

This commit is contained in:
2024-12-25 16:06:35 +01:00
parent 8bb40c7462
commit e189d1b37f
2 changed files with 14 additions and 14 deletions

View File

@@ -236,9 +236,9 @@ impl RawPacket {
}
pub enum ImprovPacket {
CurrentStateResponse(CurrentStateResponse),
CurrentState(CurrentStatePacket),
ErrorState(ErrorStatePacket),
RequestCurrentStateCommand(RequestCurrentStateCommand),
RequestCurrentState(RequestCurrentStatePacket),
RequestDeviceInformation(RequestDeviceInformationPacket),
RPCResult(RPCResultPacket),
}
@@ -246,7 +246,7 @@ pub enum ImprovPacket {
impl ImprovPacket {
pub fn try_from_raw_packet(raw_packet: &RawPacket) -> Result<Self> {
match raw_packet.r#type {
PacketType::CurrentState => Ok(ImprovPacket::CurrentStateResponse(CurrentStateResponse::try_from_raw_packet(raw_packet)?)),
PacketType::CurrentState => Ok(ImprovPacket::CurrentState(CurrentStatePacket::try_from_raw_packet(raw_packet)?)),
PacketType::ErrorState => Ok(ImprovPacket::ErrorState(ErrorStatePacket::try_from_raw_packet(raw_packet)?)),
//PacketType::RPCCommand => _,
PacketType::RPCResult => Ok(ImprovPacket::RPCResult(RPCResultPacket::try_from_raw_packet(raw_packet)?)),
@@ -255,15 +255,15 @@ impl ImprovPacket {
}
}
pub struct CurrentStateResponse {
pub struct CurrentStatePacket {
pub current_state: CurrentState,
}
impl ImprovDataPacketType for CurrentStateResponse {
impl ImprovDataPacketType for CurrentStatePacket {
const packet_type: PacketType = PacketType::CurrentState;
}
impl ImprovDataToPacket for CurrentStateResponse {
impl ImprovDataToPacket for CurrentStatePacket {
fn to_bytes(self: &Self) -> Vec<u8> {
let mut out = Vec::new();
out.push(self.current_state.clone() as u8);
@@ -271,12 +271,12 @@ impl ImprovDataToPacket for CurrentStateResponse {
}
}
impl ImprovDataFromPacket for CurrentStateResponse {
impl ImprovDataFromPacket for CurrentStatePacket {
type Error = Error;
fn try_from_raw_packet(raw_packet: &RawPacket) -> Result<Self, Self::Error>{
if raw_packet.r#type != Self::packet_type {
return Err(anyhow!("Packet is not CurrentStateResponse"));
return Err(anyhow!("Packet is not CurrentStatePacket"));
}
return Ok(Self {
@@ -307,14 +307,14 @@ impl ImprovDataFromPacket for ErrorStatePacket {
}
}
pub struct RequestCurrentStateCommand {
pub struct RequestCurrentStatePacket {
}
impl ImprovDataPacketType for RequestCurrentStateCommand {
impl ImprovDataPacketType for RequestCurrentStatePacket {
const packet_type: PacketType = PacketType::RPCCommand;
}
impl ImprovDataToPacket for RequestCurrentStateCommand {
impl ImprovDataToPacket for RequestCurrentStatePacket {
fn to_bytes(self: &Self) -> Vec<u8> {
let mut out = Vec::new();
out.push(RPCCommand::RequestCurrentState as u8);