From: Arik Sosman Date: Thu, 18 Jul 2024 08:05:19 +0000 (-0700) Subject: implement read for &mut FixedLenghtReader X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=6d611b394f8b3dc79b73cace8c3841c447b87bc4;p=rust-lightning implement read for &mut FixedLenghtReader --- diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index ec9022ca4..c93cec3db 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -153,6 +153,24 @@ impl<'a, R: Read> Read for FixedLengthReader<'a, R> { } } +impl<'a, R: Read> Read for &mut FixedLengthReader<'a, R> { + #[inline] + fn read(&mut self, dest: &mut [u8]) -> Result { + if self.total_bytes == self.bytes_read { + Ok(0) + } else { + let read_len = cmp::min(dest.len() as u64, self.total_bytes - self.bytes_read); + match self.read.read(&mut dest[0..(read_len as usize)]) { + Ok(v) => { + self.bytes_read += v as u64; + Ok(v) + }, + Err(e) => Err(e), + } + } + } +} + impl<'a, R: Read> LengthRead for FixedLengthReader<'a, R> { #[inline] fn total_bytes(&self) -> u64 {