1
0
Fork 0
forked from wry/wry

autocommit 2022-02-06 03:46:03 CET

This commit is contained in:
Julian Orth 2022-02-06 03:46:03 +01:00
parent 59ce74681a
commit c92346324b
60 changed files with 1292 additions and 1958 deletions

View file

@ -1,3 +1,4 @@
use std::rc::Rc;
use crate::fixed::Fixed;
use crate::globals::GlobalName;
use crate::object::ObjectId;
@ -65,18 +66,11 @@ impl<'a, 'b> MsgParser<'a, 'b> {
}
pub fn bstr(&mut self) -> Result<&'b BStr, MsgParserError> {
let len = self.uint()? as usize;
if len == 0 {
let s = self.array()?;
if s.len() == 0 {
return Err(MsgParserError::EmptyString);
}
let cap = (len + 3) & !3;
if cap > self.data.len() - self.pos {
return Err(MsgParserError::UnexpectedEof);
}
let s = &self.data[self.pos..self.pos + len - 1];
let s = s.as_bstr();
self.pos += cap;
Ok(s)
Ok(s[..s.len()-1].as_bstr())
}
pub fn str(&mut self) -> Result<&'b str, MsgParserError> {
@ -86,9 +80,9 @@ impl<'a, 'b> MsgParser<'a, 'b> {
}
}
pub fn fd(&mut self) -> Result<OwnedFd, MsgParserError> {
pub fn fd(&mut self) -> Result<Rc<OwnedFd>, MsgParserError> {
match self.buf.get_fd() {
Ok(fd) => Ok(fd),
Ok(fd) => Ok(Rc::new(fd)),
_ => Err(MsgParserError::MissingFd),
}
}
@ -100,4 +94,15 @@ impl<'a, 'b> MsgParser<'a, 'b> {
Err(MsgParserError::TrailingData)
}
}
pub fn array(&mut self) -> Result<&'b [u8], MsgParserError> {
let len = self.uint()? as usize;
let cap = (len + 3) & !3;
if cap > self.data.len() - self.pos {
return Err(MsgParserError::UnexpectedEof);
}
let pos = self.pos;
self.pos += cap;
Ok(&self.data[pos..pos + len])
}
}