Encode a backend message into `dst`. If this function returns an error result, `dst` is left unmodified.
(&mut self, msg: BackendMessage, dst: &mut BytesMut)
| 248 | /// Encode a backend message into `dst`. |
| 249 | /// If this function returns an error result, `dst` is left unmodified. |
| 250 | fn encode(&mut self, msg: BackendMessage, dst: &mut BytesMut) -> Result<(), io::Error> { |
| 251 | // Record the starting position so we can truncate on error. |
| 252 | // This prevents partial messages from being left in the buffer, |
| 253 | // which could be sent to the client and cause "lost synchronization" errors. |
| 254 | let start = dst.len(); |
| 255 | match self.encode_inner(msg, dst) { |
| 256 | Ok(()) => Ok(()), |
| 257 | Err(e) => { |
| 258 | dst.truncate(start); |
| 259 | Err(e) |
| 260 | } |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | impl Codec { |
no test coverage detected