summaryrefslogtreecommitdiff
path: root/src/to_clt/inv.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/to_clt/inv.rs')
-rw-r--r--src/to_clt/inv.rs37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/to_clt/inv.rs b/src/to_clt/inv.rs
new file mode 100644
index 0000000..2ada0a1
--- /dev/null
+++ b/src/to_clt/inv.rs
@@ -0,0 +1,37 @@
+use super::*;
+use mt_ser::{DeserializeError, SerializeError};
+use std::io::{Read, Write};
+
+#[mt_derive(to = "clt", custom)]
+pub struct Inventory; // TODO
+
+#[cfg(feature = "server")]
+impl MtSerialize for Inventory {
+ fn mt_serialize<C: MtCfg>(&self, writer: &mut impl Write) -> Result<(), SerializeError> {
+ "EndInventory\n".mt_serialize::<()>(writer)
+ }
+}
+
+fn read_line(reader: &mut impl Read) -> Result<String, DeserializeError> {
+ let utf8 = mt_ser::mt_deserialize_seq::<(), u8>(reader)?
+ .map_while(|x| match x {
+ Ok(0x0A) => None,
+ x => Some(x),
+ })
+ .try_collect::<Vec<_>>()?;
+
+ String::from_utf8(utf8)
+ .map_err(|e| DeserializeError::Other(format!("Invalid UTF-8: {e}").into()))
+}
+
+#[cfg(feature = "client")]
+impl MtDeserialize for Inventory {
+ fn mt_deserialize<C: MtCfg>(reader: &mut impl Read) -> Result<Self, DeserializeError> {
+ loop {
+ match read_line(reader)?.as_str() {
+ "EndInventory" => return Ok(Self),
+ _ => {}
+ }
+ }
+ }
+}