Returns the next null-terminated string. The null character is not included the returned string. The cursor is advanced past the null- terminated string. If there is no null byte remaining in the string, returns `CodecError::StringNoTerminator`. If the string is not valid UTF-8, returns an `io::Error` with an error kind of `io::ErrorKind::InvalidInput`. NOTE(benesch): it is possible that returni
(&mut self)
| 276 | /// not UTF-8 encoded. At the moment, we've not discovered a need for this, |
| 277 | /// though, and using proper strings is convenient. |
| 278 | pub fn read_cstr(&mut self) -> Result<&'a str, io::Error> { |
| 279 | if let Some(pos) = self.buf.iter().position(|b| *b == 0) { |
| 280 | let val = std::str::from_utf8(&self.buf[..pos]).map_err(input_err)?; |
| 281 | self.advance(pos + 1); |
| 282 | Ok(val) |
| 283 | } else { |
| 284 | Err(input_err(CodecError::StringNoTerminator)) |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | /// Reads the next 16-bit signed integer, advancing the cursor by two |
| 289 | /// bytes. |
no test coverage detected