(&mut self)
| 49 | } |
| 50 | |
| 51 | pub fn cstring(&mut self) -> Result<String> { |
| 52 | let start = self.offset; |
| 53 | loop { |
| 54 | let next = self |
| 55 | .buffer |
| 56 | .get(self.offset) |
| 57 | .copied() |
| 58 | .ok_or_else(|| anyhow::anyhow!("unterminated cstring"))?; |
| 59 | self.offset += 1; |
| 60 | if next == 0 { |
| 61 | let slice = &self.buffer[start..self.offset - 1]; |
| 62 | let text = std::str::from_utf8(slice)?; |
| 63 | return Ok(text.to_owned()); |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | pub fn bytes(&mut self, length: usize) -> Result<Vec<u8>> { |
| 69 | let bytes = self.take_slice(length)?; |
no outgoing calls
no test coverage detected