From 6d611b394f8b3dc79b73cace8c3841c447b87bc4 Mon Sep 17 00:00:00 2001 From: Arik Sosman Date: Thu, 18 Jul 2024 01:05:19 -0700 Subject: [PATCH] implement read for &mut FixedLenghtReader --- lightning/src/util/ser.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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 { -- 2.39.5