use crate::protocol::common::hex::decode_hex_buf;
use crate::protocol::common::hex::is_hex;
#[derive(Debug)]
pub struct ArgListHex<'a>(&'a mut [u8]);
impl<'a> ArgListHex<'a> {
pub fn from_packet(args: &'a mut [u8]) -> Option<Self> {
if args.iter().any(|b| !(is_hex(*b) || *b == b';')) {
return None;
}
Some(Self(args))
}
pub fn into_iter(self) -> impl Iterator<Item = &'a [u8]> + 'a {
self.0
.split_mut(|b| *b == b';')
.map(|raw| decode_hex_buf(raw).unwrap_or(&mut []))
.map(|s| s as &[u8])
.filter(|s| !s.is_empty())
}
}