1
0
Fork 0
forked from wry/wry

autocommit 2022-02-05 02:07:07 CET

This commit is contained in:
Julian Orth 2022-02-05 02:07:07 +01:00
parent 89bfd2ffcd
commit 2d8b3a200e
21 changed files with 328 additions and 87 deletions

View file

@ -16,6 +16,8 @@ pub enum MsgParserError {
MissingFd,
#[error("There is trailing data after the message")]
TrailingData,
#[error("String is not UTF-8")]
NonUtf8,
}
pub struct MsgParser<'a, 'b> {
@ -62,7 +64,7 @@ impl<'a, 'b> MsgParser<'a, 'b> {
self.int().map(Fixed)
}
pub fn string(&mut self) -> Result<&'b BStr, MsgParserError> {
pub fn bstr(&mut self) -> Result<&'b BStr, MsgParserError> {
let len = self.uint()? as usize;
if len == 0 {
return Err(MsgParserError::EmptyString);
@ -77,6 +79,13 @@ impl<'a, 'b> MsgParser<'a, 'b> {
Ok(s)
}
pub fn str(&mut self) -> Result<&'b str, MsgParserError> {
match self.bstr()?.to_str() {
Ok(s) => Ok(s),
_ => Err(MsgParserError::NonUtf8),
}
}
pub fn fd(&mut self) -> Result<OwnedFd, MsgParserError> {
match self.buf.get_fd() {
Ok(fd) => Ok(fd),