@@ -586,28 +586,34 @@ impl_array!(64); // for ecdsa::Signature and schnorr::Signature
586
586
impl_array ! ( 66 ) ; // for MuSig2 nonces
587
587
impl_array ! ( 1300 ) ; // for OnionPacket.hop_data
588
588
589
- impl Writeable for [ u16 ; 8 ] {
590
- #[ inline]
591
- fn write < W : Writer > ( & self , w : & mut W ) -> Result < ( ) , io:: Error > {
592
- for v in self . iter ( ) {
593
- w. write_all ( & v. to_be_bytes ( ) ) ?
589
+ macro_rules! impl_u16_array {
590
+ ( $len: expr) => {
591
+ impl Writeable for [ u16 ; $len] {
592
+ #[ inline]
593
+ fn write<W : Writer >( & self , w: & mut W ) -> Result <( ) , io:: Error > {
594
+ for v in self . iter( ) {
595
+ w. write_all( & v. to_be_bytes( ) ) ?
596
+ }
597
+ Ok ( ( ) )
598
+ }
594
599
}
595
- Ok ( ( ) )
596
- }
597
- }
598
600
599
- impl Readable for [ u16 ; 8 ] {
600
- #[ inline]
601
- fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
602
- let mut buf = [ 0u8 ; 16 ] ;
603
- r. read_exact ( & mut buf) ?;
604
- let mut res = [ 0u16 ; 8 ] ;
605
- for ( idx, v) in res. iter_mut ( ) . enumerate ( ) {
606
- * v = ( buf[ idx* 2 ] as u16 ) << 8 | ( buf[ idx* 2 + 1 ] as u16 )
601
+ impl Readable for [ u16 ; $len] {
602
+ #[ inline]
603
+ fn read<R : Read >( r: & mut R ) -> Result <Self , DecodeError > {
604
+ let mut buf = [ 0u8 ; $len* 2 ] ;
605
+ r. read_exact( & mut buf) ?;
606
+ let mut res = [ 0u16 ; $len] ;
607
+ for ( idx, v) in res. iter_mut( ) . enumerate( ) {
608
+ * v = ( buf[ idx* 2 ] as u16 ) << 8 | ( buf[ idx* 2 + 1 ] as u16 )
609
+ }
610
+ Ok ( res)
611
+ }
607
612
}
608
- Ok ( res)
609
613
}
610
614
}
615
+ impl_u16_array ! ( 8 ) ;
616
+ impl_u16_array ! ( 32 ) ;
611
617
612
618
/// A type for variable-length values within TLV record where the length is encoded as part of the record.
613
619
/// Used to prevent encoding the length twice.
0 commit comments