Encode a backend message into `dst`. If this function returns an error result, `dst` is left unmodified.
(&mut self, msg: BackendMessage, dst: &mut BytesMut)
| 143 | /// Encode a backend message into `dst`. |
| 144 | /// If this function returns an error result, `dst` is left unmodified. |
| 145 | fn encode(&mut self, msg: BackendMessage, dst: &mut BytesMut) -> Result<(), io::Error> { |
| 146 | // Record the starting position so we can truncate on error. |
| 147 | // This prevents partial messages from being left in the buffer, |
| 148 | // which could be sent to the client and cause "lost synchronization" errors. |
| 149 | let start = dst.len(); |
| 150 | match self.encode_inner(msg, dst) { |
| 151 | Ok(()) => Ok(()), |
| 152 | Err(e) => { |
| 153 | dst.truncate(start); |
| 154 | Err(e) |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | impl Codec { |
no test coverage detected