Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions crates/ember-protocol/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const MAX_BULK_LEN: i64 = 512 * 1024 * 1024;
/// Returns `Ok(Some(frame))` if a complete frame was parsed,
/// `Ok(None)` if the buffer doesn't contain enough data yet,
/// or `Err(...)` if the data is malformed.
#[inline]
pub fn parse_frame(buf: &[u8]) -> Result<Option<(Frame, usize)>, ProtocolError> {
if buf.is_empty() {
return Ok(None);
Expand Down
2 changes: 2 additions & 0 deletions crates/ember-protocol/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ impl Frame {
///
/// Writes the full RESP3 wire representation, including type prefix
/// and trailing `\r\n` delimiters.
#[inline]
pub fn serialize(&self, dst: &mut BytesMut) {
match self {
Frame::Simple(s) => {
Expand Down Expand Up @@ -63,6 +64,7 @@ impl Frame {
}

/// Writes an i64 as its decimal ASCII representation directly into the buffer.
#[inline]
fn write_i64(val: i64, dst: &mut BytesMut) {
let mut buf = itoa::Buffer::new();
dst.put_slice(buf.format(val).as_bytes());
Expand Down
20 changes: 10 additions & 10 deletions crates/ember-server/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ fn handle_sub_command(
let rx = pubsub.subscribe(&ch);
channel_rxs.insert(ch.clone(), rx);
let count = channel_rxs.len() + pattern_rxs.len();
serialize_sub_response("subscribe", &ch, count, out);
serialize_sub_response(b"subscribe", &ch, count, out);
}
}
Command::Unsubscribe { channels } => {
Expand All @@ -342,18 +342,18 @@ fn handle_sub_command(
channel_rxs.remove(&ch);
pubsub.unsubscribe(&ch);
let count = channel_rxs.len() + pattern_rxs.len();
serialize_sub_response("unsubscribe", &ch, count, out);
serialize_sub_response(b"unsubscribe", &ch, count, out);
}
if channel_rxs.is_empty() && pattern_rxs.is_empty() {
// send a final response with count 0 if we had nothing
serialize_sub_response("unsubscribe", "", 0, out);
serialize_sub_response(b"unsubscribe", "", 0, out);
}
} else {
for ch in channels {
channel_rxs.remove(&ch);
pubsub.unsubscribe(&ch);
let count = channel_rxs.len() + pattern_rxs.len();
serialize_sub_response("unsubscribe", &ch, count, out);
serialize_sub_response(b"unsubscribe", &ch, count, out);
}
}
}
Expand All @@ -377,7 +377,7 @@ fn handle_sub_command(
let rx = pubsub.psubscribe(&pat);
pattern_rxs.insert(pat.clone(), rx);
let count = channel_rxs.len() + pattern_rxs.len();
serialize_sub_response("psubscribe", &pat, count, out);
serialize_sub_response(b"psubscribe", &pat, count, out);
}
}
Command::PUnsubscribe { patterns } => {
Expand All @@ -387,17 +387,17 @@ fn handle_sub_command(
pattern_rxs.remove(&pat);
pubsub.punsubscribe(&pat);
let count = channel_rxs.len() + pattern_rxs.len();
serialize_sub_response("punsubscribe", &pat, count, out);
serialize_sub_response(b"punsubscribe", &pat, count, out);
}
if channel_rxs.is_empty() && pattern_rxs.is_empty() {
serialize_sub_response("punsubscribe", "", 0, out);
serialize_sub_response(b"punsubscribe", "", 0, out);
}
} else {
for pat in patterns {
pattern_rxs.remove(&pat);
pubsub.punsubscribe(&pat);
let count = channel_rxs.len() + pattern_rxs.len();
serialize_sub_response("punsubscribe", &pat, count, out);
serialize_sub_response(b"punsubscribe", &pat, count, out);
}
}
}
Expand Down Expand Up @@ -462,9 +462,9 @@ async fn recv_any_message(
}

/// Serializes a subscribe/unsubscribe response: ["type", channel, count]
fn serialize_sub_response(kind: &str, channel: &str, count: usize, out: &mut BytesMut) {
fn serialize_sub_response(kind: &'static [u8], channel: &str, count: usize, out: &mut BytesMut) {
Frame::Array(vec![
Frame::Bulk(Bytes::copy_from_slice(kind.as_bytes())),
Frame::Bulk(Bytes::from_static(kind)),
Frame::Bulk(Bytes::copy_from_slice(channel.as_bytes())),
Frame::Integer(count as i64),
])
Expand Down
Loading