Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(pgwire): Match on char to avoid utf8 convert #1506

Merged
merged 1 commit into from
Apr 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions rust/utils/pgwire/src/pg_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ impl FeQueryMessage {
impl FeMessage {
/// Read one message from the stream.
pub async fn read(stream: &mut (impl AsyncRead + Unpin)) -> Result<FeMessage> {
let val = &[stream.read_u8().await?];
let tag = std::str::from_utf8(val).unwrap();
let val = stream.read_u8().await?;
let len = stream.read_i32().await?;

let payload_len = len - 4;
Expand All @@ -62,9 +61,9 @@ impl FeMessage {
}
let sql_bytes = Bytes::from(payload);

match tag {
"Q" => Ok(FeMessage::Query(FeQueryMessage { sql_bytes })),
"X" => Ok(FeMessage::Terminate),
match val {
b'Q' => Ok(FeMessage::Query(FeQueryMessage { sql_bytes })),
b'X' => Ok(FeMessage::Terminate),
_ => {
unimplemented!("Do not support other tags regular message yet")
}
Expand Down