]> git.lizzy.rs Git - mt_net.git/blob - src/to_clt/inv.rs
Use cgmath and support BS constant
[mt_net.git] / src / to_clt / inv.rs
1 use super::*;
2
3 #[mt_derive(to = "clt", custom)]
4 pub struct Inventory; // TODO
5
6 #[cfg(feature = "server")]
7 impl MtSerialize for Inventory {
8     fn mt_serialize<C: MtCfg>(
9         &self,
10         writer: &mut impl std::io::Write,
11     ) -> Result<(), mt_ser::SerializeError> {
12         "EndInventory\n".mt_serialize::<()>(writer)
13     }
14 }
15
16 #[cfg(feature = "client")]
17 fn read_line(reader: &mut impl std::io::Read) -> Result<String, mt_ser::DeserializeError> {
18     let utf8 = mt_ser::mt_deserialize_seq::<(), u8>(reader)?
19         .map_while(|x| match x {
20             Ok(0x0A) => None,
21             x => Some(x),
22         })
23         .try_collect::<Vec<_>>()?;
24
25     String::from_utf8(utf8)
26         .map_err(|e| mt_ser::DeserializeError::Other(format!("Invalid UTF-8: {e}")))
27 }
28
29 #[cfg(feature = "client")]
30 impl MtDeserialize for Inventory {
31     fn mt_deserialize<C: MtCfg>(
32         reader: &mut impl std::io::Read,
33     ) -> Result<Self, mt_ser::DeserializeError> {
34         loop {
35             match read_line(reader)?.as_str() {
36                 "EndInventory" => return Ok(Self),
37                 _ => {}
38             }
39         }
40     }
41 }