/// Process some amount of received plaintext.
Process some amount of received plaintext.
Process some amount of received plaintext .
fn incoming_plaintext(
        &mut self,
        buf: &[u8],
        hashmap: &mut HashMap<i32, i32>,
        conn: &mut DatabaseConnection,
    ) {
        match self.mode {
            ServerMode::Echo => {
                let inputstr = std::str::from_utf8(buf).unwrap();
                println!("Client said: {}", inputstr);
                //default is teacher, datatype = 0
                //student, datatype = 1
                let mut datatype = 0;
                match inputstr.find("energy_teacher") {
                    Some(T) => println!("datatype is teacher!"),
                    _ => {
                        datatype = 1;
                        println!("datatype is student!")
                    }
                }
                if datatype == 1 {
                    let result: Student = serde_json::from_str(inputstr).unwrap();
                    let mut students = Vec::new();
                    let mut student = result.clone();
                    if hashmap.contains_key(&student.clientid) {
                        println!("student id {}", student.clientid);
                        let mut a = hashmap.get(&student.clientid).unwrap();
                        let mut value = a + 1;
                        hashmap.insert(student.clientid, value);
                    } else {
                        println!("student id {}", student.clientid);
                        hashmap.insert(student.clientid, 0);
                    }
                    println!(
                        "Hashmap's value is {}",
                        hashmap.get(&student.clientid).unwrap()
                    );
                    if result.sendstatus == "end" {
                        students.push(result);
                        sqlitedb::studentdao::insert_student(conn,&mut student);
                        self.tls_session.write("success\n".as_bytes()).unwrap();
                        self.tls_session.send_close_notify();
                    } else {
                        sqlitedb::studentdao::insert_student(conn,&mut student);
                        let citystring = result.city.clone();
                        students.push(result);
                        self.tls_session.write("success\n".as_bytes()).unwrap();
                    }
                } else {
                    let result: Teacher = serde_json::from_str(inputstr).unwrap();
                    let mut teachers = Vec::new();
                    let mut teacher = result.clone();
                    if hashmap.contains_key(&teacher.clientid) {
                        println!("teacher id {}", teacher.clientid);
                        let mut a = hashmap.get(&teacher.clientid).unwrap();
                        let mut value = a + 1;
                        hashmap.insert(teacher.clientid, value);
                    } else {
                        println!("teacher id {}", teacher.clientid);
                        hashmap.insert(teacher.clientid, 0);
                    }
                    println!(
                        "Hashmap's value is {}",
                        hashmap.get(&teacher.clientid).unwrap()
                    );
                    if result.sendstatus == "end" {
                        teachers.push(result);
                        sqlitedb::teacherdao::insert_teacher(conn,&mut teacher);
                        self.tls_session.write("success\n".as_bytes()).unwrap();
                        self.tls_session.send_close_notify();
                    } else {
                        sqlitedb::teacherdao::insert_teacher(conn,&mut teacher);
                        let citystring = result.city.clone();
                        teachers.push(result);
                        self.tls_session.write("success\n".as_bytes()).unwrap();
                    }
                }
                sqlitedb::opening::base_test(conn, 1);
            }
            ServerMode::Http => {
                self.send_http_response_once();
            }
            ServerMode::Forward(_) => {
                self.back.as_mut().unwrap().write_all(buf).unwrap();
            }
        }
    }
fn incoming_plaintext ( & mut self , buf : & [ u8 ] , hashmap : & mut HashMap < i32 , i32 > , conn : & mut DatabaseConnection , ) { match self . mode { ServerMode :: Echo => { let inputstr = std :: str :: from_utf8 ( buf ) . unwrap ( ) ; println ! ( " " inputstr ) ; //default is teacher, datatype = 0 //student, datatype = 1 let mut datatype = 0 ; match inputstr . find ( " " ) { Some ( T ) => println ! ( " " ) , _ => { datatype = 1 ; println ! ( " " ) } } if datatype == 1 { let result : Student = serde_json :: from_str ( inputstr ) . unwrap ( ) ; let mut students = Vec :: new ( ) ; let mut student = result . clone ( ) ; if hashmap . contains_key ( & student . clientid ) { println ! ( " " student clientid ) ; let mut a = hashmap . get ( & student . clientid ) . unwrap ( ) ; let mut value = a + 1 ; hashmap . insert ( student . clientid , value ) ; } else { println ! ( " " student clientid ) ; hashmap . insert ( student . clientid , 0 ) ; } println ! ( " " hashmap get ( student clientid ) unwrap ( ) ) ; if result . sendstatus == " " { students . push ( result ) ; sqlitedb :: studentdao :: insert_student ( conn , & mut student ) ; self . tls_session . write ( " \n " . as_bytes ( ) ) . unwrap ( ) ; self . tls_session . send_close_notify ( ) ; } else { sqlitedb :: studentdao :: insert_student ( conn , & mut student ) ; let citystring = result . city . clone ( ) ; students . push ( result ) ; self . tls_session . write ( " \n " . as_bytes ( ) ) . unwrap ( ) ; } } else { let result : Teacher = serde_json :: from_str ( inputstr ) . unwrap ( ) ; let mut teachers = Vec :: new ( ) ; let mut teacher = result . clone ( ) ; if hashmap . contains_key ( & teacher . clientid ) { println ! ( " " teacher clientid ) ; let mut a = hashmap . get ( & teacher . clientid ) . unwrap ( ) ; let mut value = a + 1 ; hashmap . insert ( teacher . clientid , value ) ; } else { println ! ( " " teacher clientid ) ; hashmap . insert ( teacher . clientid , 0 ) ; } println ! ( " " hashmap get ( teacher clientid ) unwrap ( ) ) ; if result . sendstatus == " " { teachers . push ( result ) ; sqlitedb :: teacherdao :: insert_teacher ( conn , & mut teacher ) ; self . tls_session . write ( " \n " . as_bytes ( ) ) . unwrap ( ) ; self . tls_session . send_close_notify ( ) ; } else { sqlitedb :: teacherdao :: insert_teacher ( conn , & mut teacher ) ; let citystring = result . city . clone ( ) ; teachers . push ( result ) ; self . tls_session . write ( " \n " . as_bytes ( ) ) . unwrap ( ) ; } } sqlitedb :: opening :: base_test ( conn , 1 ) ; } ServerMode :: Http => { self . send_http_response_once ( ) ; } ServerMode :: Forward ( _ ) => { self . back . as_mut ( ) . unwrap ( ) . write_all ( buf ) . unwrap ( ) ; } } }
Process some amount of received plaintext.
Process some amount of received plaintext .
&mut self
buf
&[u8]
hashmap
&mut HashMap<i32, i32>
conn
&mut DatabaseConnection