rsa_msg_packets/file/processing/
tools.rs1use crate::consts::CHUNK_SIZE;
2use anyhow::anyhow;
3use log::trace;
4
5
6pub fn get_max_chunks(size: u64) -> u64 {
7 let size_float = size as f64;
8 let chunk = CHUNK_SIZE as f64;
9
10 let threads = ((size_float / chunk).ceil()) as u64;
11 return threads;
12}
13
14pub fn get_chunk_size(chunk_index: u64, size: u64) -> anyhow::Result<u64> {
15 let left = size % CHUNK_SIZE;
16 let max_threads =get_max_chunks(size);
17
18 if chunk_index > max_threads {
19 trace!("Invalid chunk index {} with size {} and max_threads {}", chunk_index, size, max_threads);
20 return Err(anyhow!("Invalid chunk index with given size"));
21 }
22
23 if chunk_index == max_threads -1 {
24 return Ok(left);
25 }
26
27 return Ok(CHUNK_SIZE);
28}