+impl Readable for [u16; 8] {
+ #[inline]
+ fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+ let mut buf = [0u8; 16];
+ r.read_exact(&mut buf)?;
+ let mut res = [0u16; 8];
+ for (idx, v) in res.iter_mut().enumerate() {
+ *v = (buf[idx*2] as u16) << 8 | (buf[idx*2 + 1] as u16)
+ }
+ Ok(res)
+ }
+}
+
+/// A type for variable-length values within TLV record where the length is encoded as part of the record.
+/// Used to prevent encoding the length twice.
+///
+/// This is not exported to bindings users as manual TLV building is not currently supported in bindings
+pub struct WithoutLength<T>(pub T);
+
+impl Writeable for WithoutLength<&String> {
+ #[inline]
+ fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
+ w.write_all(self.0.as_bytes())
+ }
+}
+impl Readable for WithoutLength<String> {
+ #[inline]
+ fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+ let v: WithoutLength<Vec<u8>> = 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 Writeable for WithoutLength<&UntrustedString> {
+ #[inline]
+ fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
+ WithoutLength(&self.0.0).write(w)
+ }
+}
+impl Readable for WithoutLength<UntrustedString> {
+ #[inline]
+ fn read<R: Read>(r: &mut R) -> Result<Self, DecodeError> {
+ let s: WithoutLength<String> = Readable::read(r)?;
+ Ok(Self(UntrustedString(s.0)))
+ }
+}
+
+impl<'a, T: Writeable> Writeable for WithoutLength<&'a Vec<T>> {
+ #[inline]
+ fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
+ for ref v in self.0.iter() {
+ v.write(writer)?;
+ }
+ Ok(())
+ }
+}
+
+impl<T: MaybeReadable> Readable for WithoutLength<Vec<T>> {
+ #[inline]
+ fn read<R: Read>(mut reader: &mut R) -> Result<Self, DecodeError> {
+ let mut values = Vec::new();
+ loop {
+ let mut track_read = ReadTrackingReader::new(&mut reader);
+ match MaybeReadable::read(&mut track_read) {
+ Ok(Some(v)) => { values.push(v); },
+ Ok(None) => { },
+ // If we failed to read any bytes at all, we reached the end of our TLV
+ // stream and have simply exhausted all entries.
+ Err(ref e) if e == &DecodeError::ShortRead && !track_read.have_read => break,
+ Err(e) => return Err(e),
+ }
+ }
+ Ok(Self(values))
+ }
+}
+impl<'a, T> From<&'a Vec<T>> for WithoutLength<&'a Vec<T>> {
+ fn from(v: &'a Vec<T>) -> Self { Self(v) }
+}
+
+impl Writeable for WithoutLength<&Script> {
+ #[inline]
+ fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
+ writer.write_all(self.0.as_bytes())
+ }
+}
+
+impl Readable for WithoutLength<Script> {