X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=lightning%2Fsrc%2Futil%2Fser.rs;h=37fade88835a4089faea83deeb7ff7623e8ca6d0;hb=904d3229235f3a7bc5b11d95bb0e53fbb51f0da4;hp=b9722325eed04dfab630487da04e0f6b0877b2f3;hpb=227fd51cb49adaca903972464166b73468d3a257;p=rust-lightning diff --git a/lightning/src/util/ser.rs b/lightning/src/util/ser.rs index b9722325..37fade88 100644 --- a/lightning/src/util/ser.rs +++ b/lightning/src/util/ser.rs @@ -419,6 +419,9 @@ macro_rules! impl_writeable_primitive { } } } + impl From<$val_type> for HighZeroBytesDroppedBigSize<$val_type> { + fn from(val: $val_type) -> Self { Self(val) } + } } } @@ -518,6 +521,23 @@ impl Readable for [u16; 8] { /// Used to prevent encoding the length twice. pub(crate) struct WithoutLength(pub T); +impl Writeable for WithoutLength<&String> { + #[inline] + fn write(&self, w: &mut W) -> Result<(), io::Error> { + w.write_all(self.0.as_bytes()) + } +} +impl Readable for WithoutLength { + #[inline] + fn read(r: &mut R) -> Result { + let v: WithoutLength> = Readable::read(r)?; + Ok(Self(String::from_utf8(v.0).map_err(|_| DecodeError::InvalidValue)?)) + } +} +impl<'a> From<&'a String> for WithoutLength<&'a String> { + fn from(s: &'a String) -> Self { Self(s) } +} + impl<'a, T: Writeable> Writeable for WithoutLength<&'a Vec> { #[inline] fn write(&self, writer: &mut W) -> Result<(), io::Error> {