/// encoded in several different ways, which we must check for at deserialization-time. Thus, if
/// you're looking for an example of a variable-length integer to use for your own project, move
/// along, this is a rather poor design.
-pub(crate) struct BigSize(pub u64);
+pub struct BigSize(pub u64);
impl Writeable for BigSize {
#[inline]
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
impl_array!(32); // for channel id & hmac
impl_array!(PUBLIC_KEY_SIZE); // for PublicKey
impl_array!(COMPACT_SIGNATURE_SIZE); // for Signature
+impl_array!(162); // for ECDSA adaptor signatures
impl_array!(1300); // for OnionPacket.hop_data
// HashMap
// You may not use this file except in accordance with one or both of these
// licenses.
+//! Useful macros for generating serialization related code.
+
+/// Encode a TLV
+#[macro_export]
macro_rules! encode_tlv {
($stream: expr, $type: expr, $field: expr, required) => {
BigSize($type).write($stream)?;
};
}
+/// Encode a varint length prefixed TLV
+#[macro_export]
macro_rules! encode_varint_length_prefixed_tlv {
($stream: expr, {$(($type: expr, $field: expr, $fieldty: ident)),*}) => { {
use util::ser::BigSize;
}};
}
+/// Decode a TLV.
+#[macro_export]
macro_rules! decode_tlv {
($reader: expr, $field: ident, required) => {{
- $field = ser::Readable::read(&mut $reader)?;
+ $field = $crate::util::ser::Readable::read(&mut $reader)?;
}};
($reader: expr, $field: ident, vec_type) => {{
- $field = Some(ser::Readable::read(&mut $reader)?);
+ $field = Some($crate::util::ser::Readable::read(&mut $reader)?);
}};
($reader: expr, $field: ident, option) => {{
- $field = Some(ser::Readable::read(&mut $reader)?);
+ $field = Some($crate::util::ser::Readable::read(&mut $reader)?);
}};
}