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

Function decode_startup

src/pgwire-common/src/codec.rs:83–125  ·  view source on GitHub ↗
(mut conn: A)

Source from the content-addressed store, hash-verified

81}
82
83pub async fn decode_startup<A>(mut conn: A) -> Result<Option<FrontendStartupMessage>, io::Error>
84where
85 A: AsyncRead + Unpin,
86{
87 let mut frame_len = [0; 4];
88 let nread = netio::read_exact_or_eof(&mut conn, &mut frame_len).await?;
89 match nread {
90 // Complete frame length. Continue.
91 4 => (),
92 // Connection closed cleanly. Indicate that the startup sequence has
93 // been terminated by the client.
94 0 => return Ok(None),
95 // Partial frame length. Likely a client bug or network glitch, so
96 // surface the unexpected EOF.
97 _ => return Err(io::Error::new(io::ErrorKind::UnexpectedEof, "early eof")),
98 };
99 let frame_len = parse_frame_len(&frame_len)?;
100
101 let mut buf = BytesMut::new();
102 buf.resize(frame_len, b'0');
103 conn.read_exact(&mut buf).await?;
104
105 let mut buf = Cursor::new(&buf);
106 let version = buf.read_i32()?;
107 let message = match version {
108 VERSION_CANCEL => FrontendStartupMessage::CancelRequest {
109 conn_id: buf.read_u32()?,
110 secret_key: buf.read_u32()?,
111 },
112 VERSION_SSL => FrontendStartupMessage::SslRequest,
113 VERSION_GSSENC => FrontendStartupMessage::GssEncRequest,
114 _ => {
115 let mut params = BTreeMap::new();
116 while buf.peek_byte()? != 0 {
117 let name = buf.read_cstr()?.to_owned();
118 let value = buf.read_cstr()?.to_owned();
119 params.insert(name, value);
120 }
121 FrontendStartupMessage::Startup { version, params }
122 }
123 };
124 Ok(Some(message))
125}
126
127impl FrontendStartupMessage {
128 /// Encodes self into dst.

Callers 2

handle_connectionMethod · 0.85
handle_connectionMethod · 0.85

Calls 9

read_exact_or_eofFunction · 0.85
parse_frame_lenFunction · 0.85
resizeMethod · 0.80
read_i32Method · 0.80
read_u32Method · 0.80
peek_byteMethod · 0.80
read_cstrMethod · 0.80
to_ownedMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected