pub fn load_window(&mut self, file: &mut File, config: &Config){
        // if it read the whole file, do nothing
        if self.file_read {
            config.vlog("No more parts to read, as EOF occured");
            return;
        }

        // compute indices of parts to load
        let loaded_parts = Wrapping(self.loaded_parts.len() as u16);
        let mut load_index = Wrapping(self.window_position) + loaded_parts;
        let end_index = Wrapping(self.window_position) + Wrapping(self.static_properties.window_size);
        // decide how much data to load per packet
        let load_size = self.static_properties.packet_size - self.static_properties.checksum_size;
        let load_size = load_size as usize - PacketHeader::bin_size();
        config.vlog(&format!(
            "Connection {} has {} loaded parts, window size is {}, gonna be loaded {} parts, each of size {}",
            self.static_properties.id,
            loaded_parts.0,
            self.static_properties.window_size,
            self.static_properties.window_size - loaded_parts.0,
            load_size
        ));

        // load data
        let mut buffer = vec![0;load_size];
        while load_index != end_index {
            let read_size = file.read(buffer.as_mut_slice()).expect("Can't read file");
            config.vlog(&format!("Read {}b from file", read_size));
            if read_size == 0 { // if nothing read then it is end of the file
                self.file_read = true;
                break;
            }
            let part = Part {
                content: Vec::from(&buffer[..read_size]),
                last_transition: Instant::now(),
                seq: load_index.0,
                send: false,
            };
            config.vlog(&format!("Stored as part with seq {} and {}b of data", part.seq, part.content.len()));
            if let Some(_) = self.loaded_parts.insert(load_index.0, part){
                panic!("Part with this number os already loaded");
            }
            load_index += Wrapping::<u16>(1);
        }
    }
/// Load content from the `file` to fill up the window.
Load content from the `file` to fill up the window.
Load content from the ` file ` to fill up the window .
pub fn load_window(&mut self, file: &mut File, config: &Config){
        // if it read the whole file, do nothing
        if self.file_read {
            config.vlog("No more parts to read, as EOF occured");
            return;
        }
        // compute indices of parts to load
        let loaded_parts = Wrapping(self.loaded_parts.len() as u16);
        let mut load_index = Wrapping(self.window_position) + loaded_parts;
        let end_index = Wrapping(self.window_position) + Wrapping(self.static_properties.window_size);
        // decide how much data to load per packet
        let load_size = self.static_properties.packet_size - self.static_properties.checksum_size;
        let load_size = load_size as usize - PacketHeader::bin_size();
        config.vlog(&format!(
            "Connection {} has {} loaded parts, window size is {}, gonna be loaded {} parts, each of size {}",
            self.static_properties.id,
            loaded_parts.0,
            self.static_properties.window_size,
            self.static_properties.window_size - loaded_parts.0,
            load_size
        ));
        // load data
        let mut buffer = vec![0;load_size];
        while load_index != end_index {
            let read_size = file.read(buffer.as_mut_slice()).expect("Can't read file");
            config.vlog(&format!("Read {}b from file", read_size));
            if read_size == 0 { // if nothing read then it is end of the file
                self.file_read = true;
                break;
            }
            let part = Part {
                content: Vec::from(&buffer[..read_size]),
                last_transition: Instant::now(),
                seq: load_index.0,
                send: false,
            };
            config.vlog(&format!("Stored as part with seq {} and {}b of data", part.seq, part.content.len()));
            if let Some(_) = self.loaded_parts.insert(load_index.0, part){
                panic!("Part with this number os already loaded");
            }
            load_index += Wrapping::<u16>(1);
        }
    }
pub fn load_window ( & mut self , file : & mut File , config : & Config ) { // if it read the whole file, do nothing if self . file_read { config . vlog ( " " ) ; return ; } // compute indices of parts to load let loaded_parts = Wrapping ( self . loaded_parts . len ( ) as u16 ) ; let mut load_index = Wrapping ( self . window_position ) + loaded_parts ; let end_index = Wrapping ( self . window_position ) + Wrapping ( self . static_properties . window_size ) ; // decide how much data to load per packet let load_size = self . static_properties . packet_size - self . static_properties . checksum_size ; let load_size = load_size as usize - PacketHeader :: bin_size ( ) ; config . vlog ( & format ! ( " " self static_properties id loaded_parts 0 self static_properties window_size self static_properties window_size loaded_parts 0 load_size ) ) ; // load data let mut buffer = vec ! [ 0 load_size ] ; while load_index != end_index { let read_size = file . read ( buffer . as_mut_slice ( ) ) . expect ( " " ) ; config . vlog ( & format ! ( " " read_size ) ) ; if read_size == 0 { // if nothing read then it is end of the file self . file_read = true ; break ; } let part = Part { content : Vec :: from ( & buffer [ .. read_size ] ) , last_transition : Instant :: now ( ) , seq : load_index . 0 , send : false , } ; config . vlog ( & format ! ( " " part seq part content len ( ) ) ) ; if let Some ( _ ) = self . loaded_parts . insert ( load_index . 0 , part ) { panic ! ( " " ) ; } load_index += Wrapping :: < u16 > ( 1 ) ; } }
Load content from the `file` to fill up the window.
Load content from the ` file ` to fill up the window .
&mut self
file
&mut File
config
&Config
&mut self
file
&mut File
config
&Config