Encodes self into dst.
(&self, dst: &mut BytesMut)
| 127 | impl FrontendStartupMessage { |
| 128 | /// Encodes self into dst. |
| 129 | pub fn encode(&self, dst: &mut BytesMut) -> Result<(), io::Error> { |
| 130 | // Write message length placeholder. The true length is filled in later. |
| 131 | let base = dst.len(); |
| 132 | dst.put_u32(0); |
| 133 | |
| 134 | // Write message contents. |
| 135 | match self { |
| 136 | FrontendStartupMessage::Startup { version, params } => { |
| 137 | dst.put_i32(*version); |
| 138 | for (k, v) in params { |
| 139 | dst.put_string(k); |
| 140 | dst.put_string(v); |
| 141 | } |
| 142 | dst.put_i8(0); |
| 143 | } |
| 144 | FrontendStartupMessage::CancelRequest { |
| 145 | conn_id, |
| 146 | secret_key, |
| 147 | } => { |
| 148 | dst.put_i32(VERSION_CANCEL); |
| 149 | dst.put_u32(*conn_id); |
| 150 | dst.put_u32(*secret_key); |
| 151 | } |
| 152 | FrontendStartupMessage::SslRequest {} => dst.put_i32(VERSION_SSL), |
| 153 | FrontendStartupMessage::GssEncRequest => panic!("unsupported"), |
| 154 | } |
| 155 | |
| 156 | let len = dst.len() - base; |
| 157 | |
| 158 | // Overwrite length placeholder with true length. |
| 159 | let len = i32::try_from(len).map_err(|_| { |
| 160 | io::Error::new( |
| 161 | io::ErrorKind::InvalidData, |
| 162 | "length of encoded message does not fit into an i32", |
| 163 | ) |
| 164 | })?; |
| 165 | dst[base..base + 4].copy_from_slice(&len.to_be_bytes()); |
| 166 | |
| 167 | Ok(()) |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | impl FrontendMessage { |
nothing calls this directly
no test coverage detected