Created
August 5, 2020 19:05
-
-
Save bobmcwhirter/6010f9a8adb47a5fef1669e7fd4e27ff to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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