at_commands/lowlevel/
response.rs1use crate::lowlevel::arguments;
11use crate::lowlevel::write_to::WriteTo;
12use std::io;
13
14#[derive(Debug, Clone, PartialEq)]
16pub enum Response {
17 Ok,
20 Error,
23 HardcodedError(HardcodedError),
25 CmeError(i64),
27 Success { name: String, is_extension: bool, arguments: arguments::DelimitedArguments },
29 RawBytes(Vec<u8>),
31}
32
33impl WriteTo for Response {
34 fn write_to<W: io::Write>(&self, sink: &mut W) -> io::Result<()> {
35 sink.write_all(b"\r\n")?;
37 match self {
38 Response::Ok => sink.write_all(b"OK")?,
39 Response::Error => sink.write_all(b"ERROR")?,
40 Response::HardcodedError(error) => error.write_to(sink)?,
41 Response::CmeError(error_code) => {
42 sink.write_all(b"+CME ERROR: ")?;
43 sink.write_all(error_code.to_string().as_bytes())?;
44 }
45 Response::Success { name, is_extension, arguments } => {
46 if *is_extension {
47 sink.write_all(b"+")?
48 }
49 sink.write_all(name.as_bytes())?;
50 arguments.write_to(sink)?;
51 }
52 Response::RawBytes(bytes) => sink.write_all(bytes)?,
53 };
54 sink.write_all(b"\r\n")
56 }
57}
58
59#[derive(Debug, Clone, PartialEq)]
61pub enum HardcodedError {
62 NoCarrier,
63 Busy,
64 NoAnswer,
65 Delayed,
66 Blacklist,
67}
68
69impl WriteTo for HardcodedError {
70 fn write_to<W: io::Write>(&self, sink: &mut W) -> io::Result<()> {
71 match self {
72 HardcodedError::NoCarrier => sink.write_all(b"NO CARRIER"),
73 HardcodedError::Busy => sink.write_all(b"BUSY"),
74 HardcodedError::NoAnswer => sink.write_all(b"NO ANSWER"),
75 HardcodedError::Delayed => sink.write_all(b"DELAYED"),
76 HardcodedError::Blacklist => sink.write_all(b"BLACKLIST"),
77 }
78 }
79}