@@ -24,32 +24,22 @@ pub(super) trait DecodeMut<'a, 's, S>: Sized {
2424}
2525
2626macro_rules! rpc_encode_decode {
27- ( uleb128 $ty: ty) => {
27+ ( le $ty: ty) => {
2828 impl <S > Encode <S > for $ty {
29- fn encode( mut self , w: & mut Writer , s: & mut S ) {
30- let mut byte = 0x80 ;
31- while byte & 0x80 != 0 {
32- byte = ( self & 0x7f ) as u8 ;
33- self >>= 7 ;
34- if self != 0 {
35- byte |= 0x80 ;
36- }
37- byte. encode( w, s) ;
38- }
29+ fn encode( self , w: & mut Writer , _: & mut S ) {
30+ w. write_all( & self . to_le_bytes( ) ) . unwrap( ) ;
3931 }
4032 }
4133
4234 impl <S > DecodeMut <' _, ' _, S > for $ty {
43- fn decode( r: & mut Reader <' _>, s: & mut S ) -> Self {
44- let mut byte = 0x80 ;
45- let mut v = 0 ;
46- let mut shift = 0 ;
47- while byte & 0x80 != 0 {
48- byte = u8 :: decode( r, s) ;
49- v |= ( ( byte & 0x7f ) as Self ) << shift;
50- shift += 7 ;
51- }
52- v
35+ fn decode( r: & mut Reader <' _>, _: & mut S ) -> Self {
36+ const N : usize = :: std:: mem:: size_of:: <$ty>( ) ;
37+
38+ let mut bytes = [ 0 ; N ] ;
39+ bytes. copy_from_slice( & r[ ..N ] ) ;
40+ * r = & r[ N ..] ;
41+
42+ Self :: from_le_bytes( bytes)
5343 }
5444 }
5545 } ;
@@ -136,8 +126,8 @@ impl<S> DecodeMut<'_, '_, S> for u8 {
136126 }
137127}
138128
139- rpc_encode_decode ! ( uleb128 u32 ) ;
140- rpc_encode_decode ! ( uleb128 usize ) ;
129+ rpc_encode_decode ! ( le u32 ) ;
130+ rpc_encode_decode ! ( le usize ) ;
141131
142132impl < S > Encode < S > for bool {
143133 fn encode ( self , w : & mut Writer , s : & mut S ) {
0 commit comments