(&mut self, buf: &mut BytesMut)
| 139 | } |
| 140 | |
| 141 | fn process_set(&mut self, buf: &mut BytesMut) -> Result<Option<RedisClientMsg>, io::Error> { |
| 142 | if let DecodeState::Set { |
| 143 | fh, |
| 144 | key: _, |
| 145 | dsz: _, |
| 146 | rem, |
| 147 | } = &mut self.d_state |
| 148 | { |
| 149 | trace!("START PROCESS SET"); |
| 150 | trace!("cap: {}: len: {}", buf.capacity(), buf.len()); |
| 151 | // trace!("buf_raw: {:?}", String::from_utf8(buf.to_vec())); |
| 152 | |
| 153 | // How much is remaining? |
| 154 | trace!("rem: {}", rem); |
| 155 | |
| 156 | if *rem > 0 { |
| 157 | let r_buf = if *rem <= buf.len() { |
| 158 | // There could be excess bytes. |
| 159 | // Can finish and consume everything. |
| 160 | let (a, _) = buf.split_at(*rem); |
| 161 | a |
| 162 | } else { |
| 163 | // Not enough to finish, just take as much as we can. |
| 164 | &buf |
| 165 | }; |
| 166 | |
| 167 | let wr_b = fh.write(r_buf).map_err(|e| { |
| 168 | error!(?e, "Failed to write to fh"); |
| 169 | io::Error::new(io::ErrorKind::Other, "Server Error") |
| 170 | })?; |
| 171 | *rem -= wr_b; |
| 172 | trace!("wrote: {} rem: {} buflen: {}", wr_b, rem, buf.len()); |
| 173 | |
| 174 | if wr_b == buf.len() { |
| 175 | buf.clear(); |
| 176 | } else { |
| 177 | buf.advance(wr_b); |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | let r = if *rem == 0 { |
| 182 | // We don't need to read anything but we still need the crlf. |
| 183 | match tag_eol(buf) { |
| 184 | Ok(_) => { |
| 185 | // We ignore the OK inners since this is the remaining / trailing bytes. |
| 186 | // Since we'll advance by the correct len here, we don't need to |
| 187 | // do anything else. |
| 188 | let wr_b = 2; |
| 189 | trace!("COMPLETE!!! {} {}", wr_b, buf.len()); |
| 190 | if wr_b == buf.len() { |
| 191 | buf.clear(); |
| 192 | } else { |
| 193 | buf.advance(wr_b); |
| 194 | }; |
| 195 | |
| 196 | // (2, Some(...)) |
| 197 | let mut n_state = DecodeState::Cmd; |
| 198 | std::mem::swap(&mut n_state, &mut self.d_state); |
no test coverage detected