4 Commits

Author SHA1 Message Date
Corentin LIAUD
373a5265a0 chore: v2.1.17 2025-09-21 11:42:58 +02:00
yohane
060e43590d Fix:Regex expression parsing transport incorrectly 2025-09-21 11:37:37 +02:00
Corentin LIAUD
f51ba984ca impr: further improve LogFilter by removing split_inclusive 2025-09-21 11:29:05 +02:00
0vercl0k
66ebc8a030 Reword logic in LogFilter::write to avoid cloning the internal buffer 2025-09-21 11:29:05 +02:00
3 changed files with 18 additions and 13 deletions

View File

@@ -9,7 +9,7 @@ homepage = "https://github.com/cocool97/adb_client"
keywords = ["adb", "android", "tcp", "usb"]
license = "MIT"
repository = "https://github.com/cocool97/adb_client"
version = "2.1.16"
version = "2.1.17"
rust-version = "1.85.1"
# To build locally when working on a new release

View File

@@ -93,7 +93,7 @@ impl TryFrom<&[u8]> for DeviceLong {
.ok_or(RustADBError::RegexParsingError)?
.as_bytes(),
)?,
16,
10,
)?,
})
}

View File

@@ -23,21 +23,26 @@ impl<W: Write> LogFilter<W> {
impl<W: Write> Write for LogFilter<W> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
// Add newly received bytes to the internal buffer
self.buffer.extend_from_slice(buf);
let buf_clone = self.buffer.clone();
let mut lines = buf_clone.split_inclusive(|&byte| byte == b'\n').peekable();
let mut processed = 0;
while let Some(pos) = self.buffer[processed..].iter().position(|&b| b == b'\n') {
// Found a newline, need to process it
let end = processed + pos + 1; // +1 to include the '\n'
let line = &self.buffer[processed..end];
while let Some(line) = lines.next() {
if lines.peek().is_some() {
if self.should_write(line) {
self.writer.write_all(line)?;
}
} else {
// This is the last (unfinished) element, we keep it for next round
self.buffer = line.to_vec();
break;
if self.should_write(line) {
self.writer.write_all(line)?;
}
processed = end;
}
// Keep only remaining bytes after the last complete line
if processed > 0 {
self.buffer.copy_within(processed.., 0);
self.buffer.truncate(self.buffer.len() - processed);
}
Ok(buf.len())