mirror of
https://github.com/arampoire/nut-rs.git
synced 2025-11-30 16:20:25 -05:00
WIP
This commit is contained in:
parent
2224c1dd6b
commit
92779d7a33
1 changed files with 31 additions and 3 deletions
|
|
@ -9,8 +9,6 @@ macro_rules! impl_words {
|
||||||
)*
|
)*
|
||||||
) => {
|
) => {
|
||||||
pub(crate) enum Word {
|
pub(crate) enum Word {
|
||||||
/// A string argument.
|
|
||||||
Arg,
|
|
||||||
/// End-of-line.
|
/// End-of-line.
|
||||||
EOL,
|
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<Option<Self>> {
|
||||||
|
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.
|
/// Encodes a `Word` into a string.
|
||||||
/// This function cannot encode `Arg` or `EOL` (either returns `None`).
|
/// This function cannot encode `Arg` or `EOL` (either returns `None`).
|
||||||
pub(crate) fn encode(&self) -> Option<&str> {
|
pub(crate) fn encode(&self) -> Option<&str> {
|
||||||
match self {
|
match self {
|
||||||
Self::Arg | Self::EOL => None,
|
Self::EOL => None,
|
||||||
$(Self::$name => Some($word),)*
|
$(Self::$name => Some($word),)*
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -110,3 +120,21 @@ impl_words! {
|
||||||
/// Client requests the server version.
|
/// Client requests the server version.
|
||||||
Version("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 },
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue