zenoh_codec/scouting/
mod.rs1mod hello;
15mod scout;
16
17use zenoh_buffers::{
18 reader::{DidntRead, Reader},
19 writer::{DidntWrite, Writer},
20};
21use zenoh_protocol::{
22 common::imsg,
23 scouting::{id, ScoutingBody, ScoutingMessage},
24};
25
26use crate::{RCodec, WCodec, Zenoh080, Zenoh080Header};
27
28impl<W> WCodec<&ScoutingMessage, &mut W> for Zenoh080
29where
30 W: Writer,
31{
32 type Output = Result<(), DidntWrite>;
33
34 fn write(self, writer: &mut W, x: &ScoutingMessage) -> Self::Output {
35 let ScoutingMessage { body, .. } = x;
36
37 match body {
38 ScoutingBody::Scout(s) => self.write(&mut *writer, s),
39 ScoutingBody::Hello(h) => self.write(&mut *writer, h),
40 }
41 }
42}
43
44impl<R> RCodec<ScoutingMessage, &mut R> for Zenoh080
45where
46 R: Reader,
47{
48 type Error = DidntRead;
49
50 fn read(self, reader: &mut R) -> Result<ScoutingMessage, Self::Error> {
51 let header: u8 = self.read(&mut *reader)?;
52 let codec = Zenoh080Header::new(header);
53
54 let body = match imsg::mid(codec.header) {
55 id::SCOUT => ScoutingBody::Scout(codec.read(&mut *reader)?),
56 id::HELLO => ScoutingBody::Hello(codec.read(&mut *reader)?),
57 _ => return Err(DidntRead),
58 };
59 Ok(body.into())
60 }
61}