async_coap/send_desc/
ping.rs1use super::*;
17
18#[derive(Debug)]
20pub struct Ping;
21
22impl Ping {
23 #[inline]
25 pub fn new() -> Ping {
26 Ping
27 }
28}
29
30impl Default for Ping {
31 #[inline]
32 fn default() -> Self {
33 Ping
34 }
35}
36
37impl<IC: InboundContext> SendDesc<IC> for Ping {
38 fn write_options(
39 &self,
40 _msg: &mut dyn OptionInsert,
41 _socket_addr: &IC::SocketAddr,
42 _start: Bound<OptionNumber>,
43 _end: Bound<OptionNumber>,
44 ) -> Result<(), Error> {
45 Ok(())
46 }
47
48 fn write_payload(
49 &self,
50 msg: &mut dyn MessageWrite,
51 _socket_addr: &IC::SocketAddr,
52 ) -> Result<(), Error> {
53 msg.set_msg_code(MsgCode::Empty);
54 msg.set_msg_type(MsgType::Con);
55 msg.set_msg_token(MsgToken::EMPTY);
56 Ok(())
57 }
58
59 fn handler(&mut self, context: Result<&IC, Error>) -> Result<ResponseStatus<()>, Error> {
60 let context = context?;
61 if context.message().msg_type() == MsgType::Res {
62 Ok(ResponseStatus::Done(()))
63 } else {
64 Err(Error::BadResponse)
65 }
66 }
67}