Helper functions
(buf: &mut &[u8])
| 412 | |
| 413 | // Helper functions |
| 414 | fn read_cstring(buf: &mut &[u8]) -> io::Result<String> { |
| 415 | let null_pos = buf.iter().position(|&b| b == 0) |
| 416 | .ok_or_else(|| io::Error::new(io::ErrorKind::UnexpectedEof, "Missing null terminator"))?; |
| 417 | |
| 418 | let string = String::from_utf8(buf[..null_pos].to_vec()) |
| 419 | .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; |
| 420 | |
| 421 | *buf = &buf[null_pos + 1..]; |
| 422 | Ok(string) |
| 423 | } |
| 424 | |
| 425 | fn put_cstring(dst: &mut BytesMut, s: &str) { |
| 426 | dst.put_slice(s.as_bytes()); |
no outgoing calls
no test coverage detected