From 81ece1ef42b4d2987e65f7b26f01b92380b7ec32 Mon Sep 17 00:00:00 2001 From: Arik Sosman Date: Fri, 2 Aug 2024 00:54:55 -0700 Subject: [PATCH] Use adapter instead of custom consensus_decode method. --- lightning/src/util/ser.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index 738d58bc0..83c80e804 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -14,7 +14,7 @@ //! [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor use crate::prelude::*; -use crate::io::{self, Read, Seek, Write}; +use crate::io::{self, BufRead, Read, Seek, Write}; use crate::io_extras::{copy, sink}; use core::hash::Hash; use crate::sync::{Mutex, RwLock}; @@ -64,6 +64,24 @@ impl Writer for W { } } +pub(crate) struct ReadBufReadAdapter(pub R); + +impl Read for ReadBufReadAdapter { + fn read(&mut self, buf: &mut [u8]) -> io::Result { + self.0.read(buf) + } +} + +impl BufRead for ReadBufReadAdapter { + fn fill_buf(&mut self) -> io::Result<&[u8]> { + todo!() + } + + fn consume(&mut self, amount: usize) { + todo!() + } +} + pub(crate) struct WriterWriteAdaptor<'a, W: Writer + 'a>(pub &'a mut W); impl<'a, W: Writer + 'a> Write for WriterWriteAdaptor<'a, W> { #[inline] @@ -1272,7 +1290,7 @@ macro_rules! impl_consensus_ser { impl Readable for $bitcoin_type { fn read(r: &mut R) -> Result { - match consensus::encode::Decodable::consensus_decode_read(r) { + match consensus::encode::Decodable::consensus_decode(&mut ReadBufReadAdapter(r)) { Ok(t) => Ok(t), Err(consensus::encode::Error::Io(ref e)) if e.kind() == io::ErrorKind::UnexpectedEof => Err(DecodeError::ShortRead), Err(consensus::encode::Error::Io(e)) => Err(DecodeError::Io(e.kind().into())), -- 2.39.5