1 use super::prelude::*; 2 3 #[derive(Debug)] 4 pub struct qSupported<'a> { 5 pub packet_buffer_len: usize, 6 pub features: Features<'a>, 7 } 8 9 impl<'a> ParseCommand<'a> for qSupported<'a> { 10 #[inline(always)] from_packet(buf: PacketBuf<'a>) -> Option<Self>11 fn from_packet(buf: PacketBuf<'a>) -> Option<Self> { 12 let packet_buffer_len = buf.full_len(); 13 let body = buf.into_body(); 14 match body { 15 [b':', body @ ..] => Some(qSupported { 16 packet_buffer_len, 17 features: Features(body), 18 }), 19 _ => None, 20 } 21 } 22 } 23 24 #[derive(Debug)] 25 pub struct Features<'a>(&'a [u8]); 26 27 impl<'a> Features<'a> { into_iter(self) -> impl Iterator<Item = Result<Option<(Feature, bool)>, ()>> + 'a28 pub fn into_iter(self) -> impl Iterator<Item = Result<Option<(Feature, bool)>, ()>> + 'a { 29 self.0.split(|b| *b == b';').map(|s| match s.last() { 30 None => Err(()), 31 Some(&c) => match c { 32 b'+' | b'-' => { 33 let feature = match &s[..s.len() - 1] { 34 b"multiprocess" => Feature::Multiprocess, 35 // TODO: implementing other features will require IDET plumbing 36 _ => return Ok(None), 37 }; 38 Ok(Some((feature, c == b'+'))) 39 } 40 _ => { 41 // TODO: add support for "xmlRegisters=" 42 // that's the only feature packet that uses an '=', and AFAIK, it's not really 43 // used anymore... 44 Ok(None) 45 } 46 }, 47 }) 48 } 49 } 50 51 #[derive(Debug)] 52 pub enum Feature { 53 Multiprocess, 54 } 55