/// Writes data as mysql packet and returns new seq_id value.
Writes data as mysql packet and returns new seq_id value.
Writes data as mysql packet and returns new seq_id value .
fn write_packet(&mut self, data: &[u8], mut seq_id: u8, max_allowed_packet: usize) -> MyResult<u8> {
        if data.len() > max_allowed_packet &&
           max_allowed_packet < consts::MAX_PAYLOAD_LEN {
            return Err(MyDriverError(PacketTooLarge));
        }
        if data.len() == 0 {
            try!(self.write(&[0u8, 0u8, 0u8, seq_id]));
            return Ok(seq_id + 1);
        }
        let mut last_was_max = false;
        for chunk in data.chunks(consts::MAX_PAYLOAD_LEN) {
            let chunk_len = chunk.len();
            let mut writer = Vec::with_capacity(4 + chunk_len);
            last_was_max = chunk_len == consts::MAX_PAYLOAD_LEN;
            try!(writer.write_le_uint_n(chunk_len as u64, 3));
            try!(writer.write_u8(seq_id));
            seq_id += 1;
            try!(writer.write(chunk));
            try!(self.write(&writer[]));
        }
        if last_was_max {
            try!(self.write(&[0u8, 0u8, 0u8, seq_id]));
            seq_id += 1;
        }
        Ok(seq_id)
    }
fn write_packet ( & mut self , data : & [ u8 ] , mut seq_id : u8 , max_allowed_packet : usize ) -> MyResult < u8 > { if data . len ( ) > max_allowed_packet && max_allowed_packet < consts :: MAX_PAYLOAD_LEN { return Err ( MyDriverError ( PacketTooLarge ) ) ; } if data . len ( ) == 0 { try ! ( self write ( [ 0u8 0u8 0u8 seq_id ] ) ) ; return Ok ( seq_id + 1 ) ; } let mut last_was_max = false ; for chunk in data . chunks ( consts :: MAX_PAYLOAD_LEN ) { let chunk_len = chunk . len ( ) ; let mut writer = Vec :: with_capacity ( 4 + chunk_len ) ; last_was_max = chunk_len == consts :: MAX_PAYLOAD_LEN ; try ! ( writer write_le_uint_n ( chunk_len as u64 3 ) ) ; try ! ( writer write_u8 ( seq_id ) ) ; seq_id += 1 ; try ! ( writer write ( chunk ) ) ; try ! ( self write ( writer [ ] ) ) ; } if last_was_max { try ! ( self write ( [ 0u8 0u8 0u8 seq_id ] ) ) ; seq_id += 1 ; } Ok ( seq_id ) }
Writes data as mysql packet and returns new seq_id value.
Writes data as mysql packet and returns new seq_id value .
&mut self
data
&[u8]
seq_id
u8
max_allowed_packet
usize