MCPcopy Create free account
hub / github.com/erans/pgsqlite / read_cstring

Function read_cstring

src/protocol/codec.rs:414–423  ·  view source on GitHub ↗

Helper functions

(buf: &mut &[u8])

Source from the content-addressed store, hash-verified

412
413// Helper functions
414fn 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
425fn put_cstring(dst: &mut BytesMut, s: &str) {
426 dst.put_slice(s.as_bytes());

Callers 2

decode_startup_messageFunction · 0.85
decode_normal_messageFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected