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

Method decode

src/pgwire/src/codec.rs:510–577  ·  view source on GitHub ↗
(&mut self, src: &mut BytesMut)

Source from the content-addressed store, hash-verified

508 type Error = io::Error;
509
510 fn decode(&mut self, src: &mut BytesMut) -> Result<Option<FrontendMessage>, io::Error> {
511 if !self.in_copy_mode && src.len() > MAX_REQUEST_SIZE {
512 return Err(io::Error::new(
513 io::ErrorKind::InvalidData,
514 format!(
515 "request larger than {}",
516 ByteSize::b(u64::cast_from(MAX_REQUEST_SIZE))
517 ),
518 ));
519 }
520 loop {
521 match self.decode_state {
522 DecodeState::Head => {
523 if src.len() < 5 {
524 return Ok(None);
525 }
526 let msg_type = src[0];
527 let frame_len = parse_frame_len(&src[1..])?;
528 src.advance(5);
529 src.reserve(frame_len);
530 self.decode_state = DecodeState::Data(msg_type, frame_len);
531 }
532
533 DecodeState::Data(msg_type, frame_len) => {
534 if src.len() < frame_len {
535 return Ok(None);
536 }
537 let buf = src.split_to(frame_len).freeze();
538 let buf = Cursor::new(&buf);
539 let msg = match msg_type {
540 // Simple query flow.
541 b'Q' => decode_query(buf)?,
542
543 // Extended query flow.
544 b'P' => decode_parse(buf)?,
545 b'D' => decode_describe(buf)?,
546 b'B' => decode_bind(buf)?,
547 b'E' => decode_execute(buf)?,
548 b'H' => decode_flush(buf)?,
549 b'S' => decode_sync(buf)?,
550 b'C' => decode_close(buf)?,
551
552 // Termination.
553 b'X' => decode_terminate(buf)?,
554
555 // Authentication.
556 b'p' => decode_auth(buf)?,
557
558 // Copy from flow.
559 b'f' => decode_copy_fail(buf)?,
560 b'd' => decode_copy_data(buf, frame_len)?,
561 b'c' => decode_copy_done(buf)?,
562
563 // Invalid.
564 _ => {
565 return Err(io::Error::new(
566 io::ErrorKind::InvalidData,
567 format!("unknown message type {}", msg_type),

Callers

nothing calls this directly

Calls 15

parse_frame_lenFunction · 0.85
DataInterface · 0.85
decode_queryFunction · 0.85
decode_parseFunction · 0.85
decode_describeFunction · 0.85
decode_bindFunction · 0.85
decode_executeFunction · 0.85
decode_flushFunction · 0.85
decode_syncFunction · 0.85
decode_closeFunction · 0.85
decode_authFunction · 0.85
decode_copy_failFunction · 0.85

Tested by

no test coverage detected