@@ -24,32 +24,22 @@ pub(super) trait DecodeMut<'a, 's, S>: Sized {
24
24
}
25
25
26
26
macro_rules! rpc_encode_decode {
27
- ( uleb128 $ty: ty) => {
27
+ ( le $ty: ty) => {
28
28
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( ) ;
39
31
}
40
32
}
41
33
42
34
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)
53
43
}
54
44
}
55
45
} ;
@@ -136,8 +126,8 @@ impl<S> DecodeMut<'_, '_, S> for u8 {
136
126
}
137
127
}
138
128
139
- rpc_encode_decode ! ( uleb128 u32 ) ;
140
- rpc_encode_decode ! ( uleb128 usize ) ;
129
+ rpc_encode_decode ! ( le u32 ) ;
130
+ rpc_encode_decode ! ( le usize ) ;
141
131
142
132
impl < S > Encode < S > for bool {
143
133
fn encode ( self , w : & mut Writer , s : & mut S ) {
0 commit comments