MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / encode_inner

Method encode_inner

src/pgwire/src/codec.rs:268–503  ·  view source on GitHub ↗

This is the meat of the encoding logic. It's a separate function so that errors returned by `?` can be handled in the outer `encode` function.

(&self, msg: BackendMessage, dst: &mut BytesMut)

Source from the content-addressed store, hash-verified

266 /// This is the meat of the encoding logic. It's a separate function so that errors returned by
267 /// `?` can be handled in the outer `encode` function.
268 fn encode_inner(&self, msg: BackendMessage, dst: &mut BytesMut) -> Result<(), io::Error> {
269 // Write type byte.
270 let byte = match &msg {
271 BackendMessage::AuthenticationOk => b'R',
272 BackendMessage::AuthenticationCleartextPassword
273 | BackendMessage::AuthenticationSASL
274 | BackendMessage::AuthenticationSASLContinue(_)
275 | BackendMessage::AuthenticationSASLFinal(_) => b'R',
276 BackendMessage::RowDescription(_) => b'T',
277 BackendMessage::DataRow(_) => b'D',
278 BackendMessage::CommandComplete { .. } => b'C',
279 BackendMessage::EmptyQueryResponse => b'I',
280 BackendMessage::ReadyForQuery(_) => b'Z',
281 BackendMessage::NoData => b'n',
282 BackendMessage::ParameterStatus(_, _) => b'S',
283 BackendMessage::PortalSuspended => b's',
284 BackendMessage::BackendKeyData { .. } => b'K',
285 BackendMessage::ParameterDescription(_) => b't',
286 BackendMessage::ParseComplete => b'1',
287 BackendMessage::BindComplete => b'2',
288 BackendMessage::CloseComplete => b'3',
289 BackendMessage::ErrorResponse(r) => {
290 if r.severity.is_error() {
291 b'E'
292 } else {
293 b'N'
294 }
295 }
296 BackendMessage::CopyInResponse { .. } => b'G',
297 BackendMessage::CopyOutResponse { .. } => b'H',
298 BackendMessage::CopyData(_) => b'd',
299 BackendMessage::CopyDone => b'c',
300 };
301 dst.put_u8(byte);
302
303 // Write message length placeholder. The true length is filled in later.
304 let base = dst.len();
305 dst.put_u32(0);
306
307 // Write message contents.
308 match msg {
309 BackendMessage::CopyInResponse {
310 overall_format,
311 column_formats,
312 }
313 | BackendMessage::CopyOutResponse {
314 overall_format,
315 column_formats,
316 } => {
317 dst.put_format_i8(overall_format);
318 if column_formats.len() > usize::try_from(i16::MAX).expect("i16::MAX is positive") {
319 return Err(io::Error::new(
320 io::ErrorKind::InvalidData,
321 format!(
322 "{} columns in COPY response, which exceeds {}",
323 column_formats.len(),
324 i16::MAX
325 ),

Callers 1

encodeMethod · 0.45

Calls 15

is_errorMethod · 0.80
put_format_i8Method · 0.80
expectMethod · 0.80
put_length_i16Method · 0.80
put_format_i16Method · 0.80
put_stringMethod · 0.80
lenMethod · 0.45
as_bytesMethod · 0.45
is_emptyMethod · 0.45
joinMethod · 0.45
to_stringMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected