fn deep_compress(rlp: &UntrustedRlp, swapper: &InvalidRlpSwapper) -> Option<ElasticArray1024<u8>> {
	let simple_swap = ||
		swapper.get_invalid(rlp.as_raw()).map(to_elastic);
	if rlp.is_data() {
		// Try to treat the inside as RLP.
		return match rlp.payload_info() {
			// Shortest decompressed account is 70, so simply try to swap the value.
			Ok(ref p) if p.value_len < 70 => simple_swap(),
			_ => {
				if let Ok(d) = rlp.data() {
					let internal_rlp = UntrustedRlp::new(d);
					if let Some(new_d) = deep_compress(&internal_rlp, swapper) {
						// If compressed put in a special list, with first element being invalid code.
						let mut rlp = RlpStream::new_list(2);
						rlp.append_raw(&[0x81, 0x7f], 1);
						rlp.append_raw(&new_d[..], 1);
						return Some(rlp.drain());
					}
				}
				simple_swap()
			},
		};
	}
	// Iterate through RLP while checking if it has been compressed.
	map_rlp(rlp, |r| deep_compress(r, swapper))
}
/// Replace common RLPs with invalid shorter ones, None if no compression achieved.
/// Tries to compress data insides.
Replace common RLPs with invalid shorter ones, None if no compression achieved.
Tries to compress data insides.
Replace common RLPs with invalid shorter ones None if no compression achieved . Tries to compress data insides .
fn deep_compress(rlp: &UntrustedRlp, swapper: &InvalidRlpSwapper) -> Option<ElasticArray1024<u8>> {
	let simple_swap = ||
		swapper.get_invalid(rlp.as_raw()).map(to_elastic);
	if rlp.is_data() {
		// Try to treat the inside as RLP.
		return match rlp.payload_info() {
			// Shortest decompressed account is 70, so simply try to swap the value.
			Ok(ref p) if p.value_len < 70 => simple_swap(),
			_ => {
				if let Ok(d) = rlp.data() {
					let internal_rlp = UntrustedRlp::new(d);
					if let Some(new_d) = deep_compress(&internal_rlp, swapper) {
						// If compressed put in a special list, with first element being invalid code.
						let mut rlp = RlpStream::new_list(2);
						rlp.append_raw(&[0x81, 0x7f], 1);
						rlp.append_raw(&new_d[..], 1);
						return Some(rlp.drain());
					}
				}
				simple_swap()
			},
		};
	}
	// Iterate through RLP while checking if it has been compressed.
	map_rlp(rlp, |r| deep_compress(r, swapper))
}
fn deep_compress ( rlp : & UntrustedRlp , swapper : & InvalidRlpSwapper ) -> Option < ElasticArray1024 < u8 > > { let simple_swap = | | swapper . get_invalid ( rlp . as_raw ( ) ) . map ( to_elastic ) ; if rlp . is_data ( ) { // Try to treat the inside as RLP. return match rlp . payload_info ( ) { // Shortest decompressed account is 70, so simply try to swap the value. Ok ( ref p ) if p . value_len < 70 => simple_swap ( ) , _ => { if let Ok ( d ) = rlp . data ( ) { let internal_rlp = UntrustedRlp :: new ( d ) ; if let Some ( new_d ) = deep_compress ( & internal_rlp , swapper ) { // If compressed put in a special list, with first element being invalid code. let mut rlp = RlpStream :: new_list ( 2 ) ; rlp . append_raw ( & [ 0x81 , 0x7f ] , 1 ) ; rlp . append_raw ( & new_d [ .. ] , 1 ) ; return Some ( rlp . drain ( ) ) ; } } simple_swap ( ) } , } ; } // Iterate through RLP while checking if it has been compressed. map_rlp ( rlp , | r | deep_compress ( r , swapper ) ) }
Replace common RLPs with invalid shorter ones, None if no compression achieved.
Replace common RLPs with invalid shorter ones None if no compression achieved .
rlp
&UntrustedRlp
swapper
&InvalidRlpSwapper