protocols command (#67)
Adds a command for getting all enabled (and disabled) protocols from the server. - **add response for protocol status** - **add command for protocols** - **allow calling `Protocols` from BinaryParser** - **allow calling `Protocols` from textparser**
This commit is contained in:
commit
f124c7c9cb
4 changed files with 67 additions and 1 deletions
|
|
@ -7,6 +7,7 @@ use crate::{Canvas, Color, Command, Response};
|
|||
use super::{IOProtocol, Parser, Responder};
|
||||
|
||||
const SIZE_BIN: u8 = 115;
|
||||
const PROTOCOLS_BIN: u8 = 116;
|
||||
const HELP_BIN: u8 = 104;
|
||||
const GET_PX_BIN: u8 = 32;
|
||||
const SET_PX_RGB_BIN: u8 = 128;
|
||||
|
|
@ -22,6 +23,7 @@ impl<R: AsyncBufRead + AsyncBufReadExt + std::marker::Unpin> Parser<R> for Binar
|
|||
match fst {
|
||||
Ok(command) => match command {
|
||||
HELP_BIN => Ok(Command::Help),
|
||||
PROTOCOLS_BIN => Ok(Command::Protocols),
|
||||
SIZE_BIN => {
|
||||
let canvas = reader.read_u8().await?;
|
||||
Ok(Command::Size(canvas))
|
||||
|
|
@ -106,6 +108,23 @@ To set a pixel using RGB, use ({SET_PX_RGB_BIN:02X}) (u8 canvas) (x as u16_le) (
|
|||
);
|
||||
writer.write_all(help_text.as_bytes()).await
|
||||
}
|
||||
Response::Protocols(protos) => {
|
||||
for protocol in protos {
|
||||
match protocol {
|
||||
crate::ProtocolStatus::Enabled(proto) => {
|
||||
writer
|
||||
.write_all(format!("Enabled: {}\n", proto).as_bytes())
|
||||
.await?;
|
||||
}
|
||||
crate::ProtocolStatus::Disabled(proto) => {
|
||||
writer
|
||||
.write_all(format!("Disabled: {}\n", proto).as_bytes())
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Response::Size(x, y) => {
|
||||
writer.write_u16(x).await?;
|
||||
writer.write_u16(y).await
|
||||
|
|
|
|||
|
|
@ -117,6 +117,8 @@ impl<R: AsyncBufRead + AsyncBufReadExt + std::marker::Unpin> Parser<R> for TextP
|
|||
if reader.read_line(&mut line).await.is_ok() {
|
||||
if line.starts_with("HELP") {
|
||||
return Ok(Command::Help);
|
||||
} else if line.starts_with("PROTOCOLS") {
|
||||
return Ok(Command::Protocols);
|
||||
} else if line.starts_with("SIZE") {
|
||||
return Ok(Command::Size(self.canvas));
|
||||
} else if line.starts_with("PX ") {
|
||||
|
|
@ -146,6 +148,23 @@ impl<W: AsyncWriteExt + std::marker::Unpin> Responder<W> for TextParser {
|
|||
async fn unparse(&self, response: Response, writer: &mut W) -> io::Result<()> {
|
||||
match response {
|
||||
Response::Help => writer.write_all(HELP_TEXT).await,
|
||||
Response::Protocols(protos) => {
|
||||
for protocol in protos {
|
||||
match protocol {
|
||||
crate::ProtocolStatus::Enabled(proto) => {
|
||||
writer
|
||||
.write_all(format!("Enabled: {}\n", proto).as_bytes())
|
||||
.await?;
|
||||
}
|
||||
crate::ProtocolStatus::Disabled(proto) => {
|
||||
writer
|
||||
.write_all(format!("Disabled: {}\n", proto).as_bytes())
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Response::Size(x, y) => writer.write_all(format!("SIZE {x} {y}\n").as_bytes()).await,
|
||||
Response::GetPixel(x, y, color) => {
|
||||
writer
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue