a few more quick changes and another range loop ignore

This commit is contained in:
Grant Wuerker 2018-10-20 17:38:32 -05:00
parent 869049d099
commit d3ec313b43
3 changed files with 6 additions and 11 deletions

View File

@ -1,3 +1,5 @@
#![cfg_attr(not(feature = "clippy"), allow(needless_range_loop))]
use super::{ use super::{
LENGTH_BYTES, LENGTH_BYTES,
}; };
@ -79,7 +81,7 @@ pub fn decode_length(bytes: &[u8], index: usize, length_bytes: usize)
let mut len: usize = 0; let mut len: usize = 0;
for i in index..index+length_bytes { for i in index..index+length_bytes {
let offset = (index+length_bytes - i - 1) * 8; let offset = (index+length_bytes - i - 1) * 8;
len = ((bytes[i] as usize) << offset) | len; len |= (bytes[i] as usize) << offset;
}; };
Ok(len) Ok(len)
} }

View File

@ -1,15 +1,9 @@
#![cfg_attr(not(feature = "clippy"), allow(needless_range_loop))] #![cfg_attr(not(feature = "clippy"), allow(needless_range_loop))]
use super::{ use super::{
LENGTH_BYTES, LENGTH_BYTES
MAX_LIST_SIZE,
}; };
#[derive(Debug)]
pub enum EncodeError {
ListTooLong,
}
pub trait Encodable { pub trait Encodable {
fn ssz_append(&self, s: &mut SszStream); fn ssz_append(&self, s: &mut SszStream);
} }

View File

@ -53,11 +53,10 @@ impl Decodable for H256 {
-> Result<(Self, usize), DecodeError> -> Result<(Self, usize), DecodeError>
{ {
if bytes.len() < 32 || bytes.len() - 32 < index { if bytes.len() < 32 || bytes.len() - 32 < index {
return Err(DecodeError::TooShort) Err(DecodeError::TooShort)
} }
else { else {
return Ok((H256::from(&bytes[index..(index + 32)]), Ok((H256::from(&bytes[index..(index + 32)]), index + 32))
index + 32));
} }
} }
} }