Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bobmcwhirter/6010f9a8adb47a5fef1669e7fd4e27ff to your computer and use it in GitHub Desktop.
Save bobmcwhirter/6010f9a8adb47a5fef1669e7fd4e27ff to your computer and use it in GitHub Desktop.
fn parse(&self, resp: &[u8]) -> Result<Self::Response, Error> {
let mut ip = Option::None;
let mut gateway = Option::None;
let mut netmask = Option::None;
for chunk in resp.split(|e| *e == b'\n') {
let line = core::str::from_utf8(chunk);
if let Ok(line) = line {
if let Some(addr_type) = extract_between(line, ':') {
if let Some(addr_value) = extract_between(line, '"') {
if let Some(addr_value) = to_address(addr_value) {
match addr_type {
"ip" => {
ip.replace(addr_value);
}
"gateway" => {
gateway.replace(addr_value);
}
"netmask" => {
netmask.replace(addr_value);
}
_ => {}
}
}
}
}
}
}
Ok(IPAddresses {
ip: ip.ok_or(Error::Read)?,
gateway: gateway.ok_or(Error::Read)?,
netmask: netmask.ok_or(Error::Read)?,
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment