Skip to content

Commit b582ce1

Browse files
committed
Drop the BufReader wrapper
Post `0.32.4` deserialization of consensus objects now use `Read` as the trait bounds, making the BufReader no longer needed for deserialization.
1 parent deee085 commit b582ce1

1 file changed

Lines changed: 1 addition & 67 deletions

File tree

lightning/src/util/ser.rs

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
1414
//! [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
1515
16-
use crate::io::{self, BufRead, Read, Write};
16+
use crate::io::{self, Read, Write};
1717
use crate::io_extras::{copy, sink};
1818
use crate::ln::interactivetxs::{TxInMetadata, TxOutMetadata};
1919
use crate::ln::onion_utils::{HMAC_COUNT, HMAC_LEN, HOLD_TIME_LEN, MAX_HOPS};
@@ -77,72 +77,6 @@ impl<W: Write> Writer for W {
7777
}
7878
}
7979

80-
// TODO: Drop this entirely if rust-bitcoin releases a version bump with https://github.com/rust-bitcoin/rust-bitcoin/pull/3173
81-
/// Wrap buffering support for implementations of Read.
82-
/// A [`Read`]er which keeps an internal buffer to avoid hitting the underlying stream directly for
83-
/// every read, implementing [`BufRead`].
84-
///
85-
/// In order to avoid reading bytes past the first object, and those bytes then ending up getting
86-
/// dropped, this BufReader operates in one-byte-increments.
87-
struct BufReader<'a, R: Read> {
88-
inner: &'a mut R,
89-
buf: [u8; 1],
90-
is_consumed: bool,
91-
}
92-
93-
impl<'a, R: Read> BufReader<'a, R> {
94-
/// Creates a [`BufReader`] which will read from the given `inner`.
95-
pub fn new(inner: &'a mut R) -> Self {
96-
BufReader { inner, buf: [0; 1], is_consumed: true }
97-
}
98-
}
99-
100-
impl<'a, R: Read> Read for BufReader<'a, R> {
101-
#[inline]
102-
fn read(&mut self, output: &mut [u8]) -> io::Result<usize> {
103-
if output.is_empty() {
104-
return Ok(0);
105-
}
106-
let mut offset = 0;
107-
if !self.is_consumed {
108-
output[0] = self.buf[0];
109-
self.is_consumed = true;
110-
offset = 1;
111-
}
112-
self.inner.read(&mut output[offset..]).map(|len| len + offset)
113-
}
114-
}
115-
116-
impl<'a, R: Read> BufRead for BufReader<'a, R> {
117-
#[inline]
118-
fn fill_buf(&mut self) -> io::Result<&[u8]> {
119-
debug_assert!(false, "rust-bitcoin doesn't actually use this");
120-
if self.is_consumed {
121-
let count = self.inner.read(&mut self.buf[..])?;
122-
debug_assert!(count <= 1, "read gave us a garbage length");
123-
124-
// upon hitting EOF, assume the byte is already consumed
125-
self.is_consumed = count == 0;
126-
}
127-
128-
if self.is_consumed {
129-
Ok(&[])
130-
} else {
131-
Ok(&self.buf[..])
132-
}
133-
}
134-
135-
#[inline]
136-
fn consume(&mut self, amount: usize) {
137-
debug_assert!(false, "rust-bitcoin doesn't actually use this");
138-
if amount >= 1 {
139-
debug_assert_eq!(amount, 1, "Can only consume one byte");
140-
debug_assert!(!self.is_consumed, "Cannot consume more than had been read");
141-
self.is_consumed = true;
142-
}
143-
}
144-
}
145-
14680
pub(crate) struct WriterWriteAdaptor<'a, W: Writer + 'a>(pub &'a mut W);
14781
impl<'a, W: Writer + 'a> Write for WriterWriteAdaptor<'a, W> {
14882
#[inline]

0 commit comments

Comments
 (0)