From 92779d7a3347c9f15ec164a42751e639e3f5c5fc Mon Sep 17 00:00:00 2001 From: Aram Peres Date: Tue, 3 Aug 2021 03:56:07 -0400 Subject: [PATCH] WIP --- rups/src/proto/mod.rs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/rups/src/proto/mod.rs b/rups/src/proto/mod.rs index 887bbb4..7533644 100644 --- a/rups/src/proto/mod.rs +++ b/rups/src/proto/mod.rs @@ -9,8 +9,6 @@ macro_rules! impl_words { )* ) => { pub(crate) enum Word { - /// A string argument. - Arg, /// End-of-line. EOL, $( @@ -36,11 +34,23 @@ macro_rules! impl_words { } } + /// Decodes a sequence of words. + /// Unrecognized words will be `None` + /// Returns a `Vec` of the same length as the given slice. + pub(crate) fn decode_words(raw: &[&str]) -> Vec> { + let mut words = Vec::new(); + for r in raw.iter() { + words.push(Self::decode(Some(r))); + } + words.push(Some(Self::EOL)); + words + } + /// Encodes a `Word` into a string. /// This function cannot encode `Arg` or `EOL` (either returns `None`). pub(crate) fn encode(&self) -> Option<&str> { match self { - Self::Arg | Self::EOL => None, + Self::EOL => None, $(Self::$name => Some($word),)* } } @@ -110,3 +120,21 @@ impl_words! { /// Client requests the server version. Version("VERSION"), } + +// impl_serverbound! { +// QueryVersion(Version, EOL), +// QueryNetworkVersion(NetworkVersion, EOL), +// QueryHelp(Help, EOL), +// QueryListUps(List, Ups, EOL), +// QueryListVar(List, Var, Arg(ups_name), EOL), +// QueryListRw(List, Rw, Arg(ups_name), EOL), +// } + +pub(crate) enum ServerboundSentence { + QueryVersion, + QueryNetworkVersion, + QueryHelp, + QueryListUps, + QueryListVar { ups_name: String }, + QueryListRw { ups_name: String }, +}