@@ -11,12 +11,12 @@ mod gps_data_codec {
1111 offset : u32 ,
1212 }
1313
14- fn decode_unsigned_value_from_string ( slice : & [ u8 ] , offset : u32 ) -> DecodingResult {
14+ fn decode_unsigned_value_from_string < ' a > ( slice : & mut impl Iterator < Item = & ' a u8 > ) -> DecodingResult {
1515 let mut result: i64 = 0 ;
1616 let mut shift = 0 ;
17- let mut position: u32 = offset ;
17+ let mut position: u32 = 0 ;
1818 loop {
19- let byte = slice[ position as usize ] - 63 ;
19+ let byte = slice. next ( ) . unwrap ( ) - 63 ;
2020 position += 1 ;
2121 if ( byte & 0x20 ) == 0 {
2222 result |= ( byte as i64 ) << shift;
@@ -31,8 +31,8 @@ mod gps_data_codec {
3131 }
3232 }
3333
34- fn decode_signed_value_from_string ( encoded : & [ u8 ] , offset : u32 ) -> DecodingResult {
35- let tmp_result: DecodingResult = decode_unsigned_value_from_string ( encoded, offset ) ;
34+ fn decode_signed_value_from_string < ' a > ( encoded : & mut impl Iterator < Item = & ' a u8 > ) -> DecodingResult {
35+ let tmp_result: DecodingResult = decode_unsigned_value_from_string ( encoded) ;
3636 if tmp_result. value & 1 == 1 {
3737 DecodingResult {
3838 value : !( tmp_result. value >> 1 ) ,
@@ -74,18 +74,18 @@ mod gps_data_codec {
7474 let mut vals: [ i64 ; 3 ] = [ YEAR2010 , 0 , 0 ] ;
7575 let mut bytes_consumed: u32 = 0 ;
7676 let mut decoding_result: DecodingResult ;
77- let encoded: & [ u8 ] = input. as_bytes ( ) ;
77+ let mut encoded = input. as_bytes ( ) . into_iter ( ) ;
7878 let encoded_length: u32 = encoded. len ( ) as u32 ;
7979 let mut output: Vec < ( i64 , f64 , f64 ) > = Vec :: new ( ) ;
8080
8181 while bytes_consumed < encoded_length {
8282 for ( i, val) in vals. iter_mut ( ) . enumerate ( ) {
8383 if i == 0 && bytes_consumed != 0 {
84- decoding_result = decode_unsigned_value_from_string ( encoded , bytes_consumed ) ;
84+ decoding_result = decode_unsigned_value_from_string ( & mut encoded ) ;
8585 } else {
86- decoding_result = decode_signed_value_from_string ( encoded , bytes_consumed ) ;
86+ decoding_result = decode_signed_value_from_string ( & mut encoded ) ;
8787 }
88- bytes_consumed = decoding_result. offset ;
88+ bytes_consumed + = decoding_result. offset ;
8989 * val += decoding_result. value ;
9090 }
9191 output. push ( ( vals[ 0 ] , ( vals[ 1 ] as f64 ) / 1e5 , ( vals[ 2 ] as f64 ) / 1e5 ) ) ;
0 commit comments