Merge pull request #1091 from TheBlueMatt/2021-09-997-winblowz
[rust-lightning] / lightning / src / util / ser.rs
index a6991c5c3d0d2a953dea4ba11993c446e37385ee..c06293269ec0ffc28727a3d2624e92a9f95d1319 100644 (file)
@@ -884,3 +884,20 @@ impl Readable for () {
                Ok(())
        }
 }
+
+impl Writeable for String {
+       #[inline]
+       fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
+               (self.len() as u16).write(w)?;
+               w.write_all(self.as_bytes())
+       }
+}
+
+impl Readable for String {
+       #[inline]
+       fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+               let v: Vec<u8> = Readable::read(r)?;
+               let ret = String::from_utf8(v).map_err(|_| DecodeError::InvalidValue)?;
+               Ok(ret)
+       }
+}