X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=inline;f=lightning%2Fsrc%2Futil%2Fser.rs;h=852aa8f15892e5bbc3d14dd265ecf7f168044653;hb=a031ff952bee42aad38edd29ede6aaa05a4cb6cb;hp=5b1a86a6a95f27a276f1dc221bd705f57fbf8ed4;hpb=29e34c8a10cf813116c9251188a86978cc97e259;p=rust-lightning
diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs
index 5b1a86a6a..852aa8f15 100644
--- a/lightning/src/util/ser.rs
+++ b/lightning/src/util/ser.rs
@@ -244,6 +244,14 @@ pub(crate) trait LengthReadableArgs
where Self: Sized
fn read(reader: &mut R, params: P) -> Result;
}
+/// A trait that various higher-level rust-lightning types implement allowing them to be read in
+/// from a Read, requiring the implementer to provide the total length of the read.
+pub(crate) trait LengthReadable where Self: Sized
+{
+ /// Reads a Self in from the given LengthRead
+ fn read(reader: &mut R) -> Result;
+}
+
/// A trait that various rust-lightning types implement allowing them to (maybe) be read in from a Read
///
/// (C-not exported) as we only export serialization to/from byte arrays instead
@@ -392,7 +400,7 @@ impl Readable for BigSize {
/// variable-length integer which is simply truncated by skipping high zero bytes. This type
/// encapsulates such integers implementing Readable/Writeable for them.
#[cfg_attr(test, derive(PartialEq, Debug))]
-pub(crate) struct HighZeroBytesDroppedVarInt(pub T);
+pub(crate) struct HighZeroBytesDroppedBigSize(pub T);
macro_rules! impl_writeable_primitive {
($val_type:ty, $len: expr) => {
@@ -402,7 +410,7 @@ macro_rules! impl_writeable_primitive {
writer.write_all(&self.to_be_bytes())
}
}
- impl Writeable for HighZeroBytesDroppedVarInt<$val_type> {
+ impl Writeable for HighZeroBytesDroppedBigSize<$val_type> {
#[inline]
fn write(&self, writer: &mut W) -> Result<(), io::Error> {
// Skip any full leading 0 bytes when writing (in BE):
@@ -417,9 +425,9 @@ macro_rules! impl_writeable_primitive {
Ok(<$val_type>::from_be_bytes(buf))
}
}
- impl Readable for HighZeroBytesDroppedVarInt<$val_type> {
+ impl Readable for HighZeroBytesDroppedBigSize<$val_type> {
#[inline]
- fn read(reader: &mut R) -> Result, DecodeError> {
+ fn read(reader: &mut R) -> Result, DecodeError> {
// We need to accept short reads (read_len == 0) as "EOF" and handle them as simply
// the high bytes being dropped. To do so, we start reading into the middle of buf
// and then convert the appropriate number of bytes with extra high bytes out of
@@ -435,7 +443,7 @@ macro_rules! impl_writeable_primitive {
let first_byte = $len - ($len - total_read_len);
let mut bytes = [0; $len];
bytes.copy_from_slice(&buf[first_byte..first_byte + $len]);
- Ok(HighZeroBytesDroppedVarInt(<$val_type>::from_be_bytes(bytes)))
+ Ok(HighZeroBytesDroppedBigSize(<$val_type>::from_be_bytes(bytes)))
} else {
// If the encoding had extra zero bytes, return a failure even though we know
// what they meant (as the TLV test vectors require this)
@@ -852,7 +860,7 @@ macro_rules! impl_consensus_ser {
($bitcoin_type: ty) => {
impl Writeable for $bitcoin_type {
fn write(&self, writer: &mut W) -> Result<(), io::Error> {
- match self.consensus_encode(WriterWriteAdaptor(writer)) {
+ match self.consensus_encode(&mut WriterWriteAdaptor(writer)) {
Ok(_) => Ok(()),
Err(e) => Err(e),
}