| fn unescape(buf: &[u8]) -> Result<Vec<u8>> {
|
| let mut res = Vec::with_capacity(512);
|
| let mut bytes = buf.bytes();
|
| while let Some(Ok(byte)) = bytes.next() {
|
| if byte == 0xFF { // Got an escape code?
|
| match bytes.next() { // Add the appropriate byte based on the following byte.
|
| Some(Ok(0xFF)) => res.push(0xFF),
|
| Some(Ok(0xFE)) => res.push(0x00),
|
| Some(Ok(0xFD)) => res.push(0x0A),
|
| Some(Ok(0xFC)) => res.push(0x0D),
|
| Some(Ok(b)) => bail!("Invalid escape sequence: 0xFF 0x{b:X}"),
|
| _ => bail!("Escaped data truncated.")
|
| }
|
| } else {
|
| res.push(byte)
|
| }
|
| }
|
| Ok(res)
|
| }
|