X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Futil%2Fser.rs;h=1bf30fa9f72e421882b1fe612da08c30b65a29eb;hb=71739dbe0495b3aed4ce907fea88c122df9ac6a1;hp=3de03ea5a0d5efd93b4c3a22e4d88845656dbf23;hpb=e61f3a238a70cbac87209e223b7c396108a49b97;p=rust-lightning diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index 3de03ea5..1bf30fa9 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -10,11 +10,11 @@ //! A very simple serialization framework which is used to serialize/deserialize messages as well //! as ChannelsManagers and ChannelMonitors. -use prelude::*; -use io::{self, Read, Write}; -use io_extras::{copy, sink}; +use crate::prelude::*; +use crate::io::{self, Read, Write}; +use crate::io_extras::{copy, sink}; use core::hash::Hash; -use sync::Mutex; +use crate::sync::Mutex; use core::cmp; use core::convert::TryFrom; use core::ops::Deref; @@ -30,10 +30,10 @@ use bitcoin::hashes::sha256d::Hash as Sha256dHash; use bitcoin::hash_types::{Txid, BlockHash}; use core::marker::Sized; use core::time::Duration; -use ln::msgs::DecodeError; -use ln::{PaymentPreimage, PaymentHash, PaymentSecret}; +use crate::ln::msgs::DecodeError; +use crate::ln::{PaymentPreimage, PaymentHash, PaymentSecret}; -use util::byte_utils::{be48_to_array, slice_to_be48}; +use crate::util::byte_utils::{be48_to_array, slice_to_be48}; /// serialization buffer size pub const MAX_BUF_SIZE: usize = 64 * 1024; @@ -269,6 +269,15 @@ impl MaybeReadable for T { } } +/// A trait that various rust-lightning types implement allowing them to (maybe) be read in from a +/// Read, given some additional set of arguments which is required to deserialize. +/// +/// (C-not exported) as we only export serialization to/from byte arrays instead +pub trait MaybeReadableArgs

{ + /// Reads a Self in from the given Read + fn read(reader: &mut R, params: P) -> Result, DecodeError> where Self: Sized; +} + pub(crate) struct OptionDeserWrapper(pub Option); impl Readable for OptionDeserWrapper { #[inline] @@ -1062,7 +1071,7 @@ impl Readable for Duration { #[cfg(test)] mod tests { use core::convert::TryFrom; - use util::ser::{Readable, Hostname, Writeable}; + use crate::util::ser::{Readable, Hostname, Writeable}; #[test] fn hostname_conversion() {