From 44e9cb08f683662662a668905aa90a95637675a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2=20=5BArtyom=20Pavlov=5D?= Date: Wed, 22 May 2024 17:11:26 +0300 Subject: [PATCH] Accept empty `latching` field --- src/record_types/chunk.rs | 7 +++---- src/record_types/connection.rs | 4 ++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/record_types/chunk.rs b/src/record_types/chunk.rs index 0872478..576e7bd 100644 --- a/src/record_types/chunk.rs +++ b/src/record_types/chunk.rs @@ -19,10 +19,10 @@ pub enum Compression { impl Compression { fn decompress(self, data: &[u8], decompressed_size: Option) -> Result> { + let decompressed_len = decompressed_size.map(|s| s as usize).unwrap_or(data.len()); Ok(match self { Compression::Bzip2 => { - let mut decompressed = Vec::new(); - decompressed.reserve(decompressed_size.map(|s| s as usize).unwrap_or(data.len())); + let mut decompressed = Vec::with_capacity(decompressed_len); let mut decompressor = bzip2::Decompress::new(false); decompressor .decompress_vec(data, &mut decompressed) @@ -32,8 +32,7 @@ impl Compression { Compression::Lz4 => { let mut decoder = lz4::Decoder::new(data) .map_err(|e| Error::Lz4DecompressionError(e.to_string()))?; - let mut decompressed = Vec::new(); - decompressed.reserve(decompressed_size.map(|s| s as usize).unwrap_or(data.len())); + let mut decompressed = Vec::with_capacity(decompressed_len); std::io::copy(&mut decoder, &mut decompressed).map_err(|_| { Error::Lz4DecompressionError("Error while decoding".to_string()) })?; diff --git a/src/record_types/connection.rs b/src/record_types/connection.rs index c592861..163c839 100644 --- a/src/record_types/connection.rs +++ b/src/record_types/connection.rs @@ -74,6 +74,10 @@ impl<'a> RecordGen<'a> for Connection<'a> { latching = match val { b"1" => true, b"0" => false, + b"" => { + log::warn!("Got empty latching field, interpreting it as 0"); + false + } _ => return Err(Error::InvalidRecord), } }