Skip to content

Commit

Permalink
CodecBuilder::protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed Feb 21, 2024
1 parent f501c7e commit 53f417f
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 12 deletions.
4 changes: 2 additions & 2 deletions shotover/src/codec/cassandra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ impl CodecBuilder for CassandraCodecBuilder {
)
}

fn websocket_subprotocol(&self) -> &'static str {
"cql"
fn protocol(&self) -> MessageType {
MessageType::Cassandra
}
}

Expand Down
4 changes: 2 additions & 2 deletions shotover/src/codec/kafka.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ impl CodecBuilder for KafkaCodecBuilder {
)
}

fn websocket_subprotocol(&self) -> &'static str {
"kafka"
fn protocol(&self) -> MessageType {
MessageType::Kafka
}
}

Expand Down
4 changes: 2 additions & 2 deletions shotover/src/codec/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Codec types to use for connecting to a DB in a sink transform
use crate::message::Messages;
use crate::{frame::MessageType, message::Messages};
#[cfg(feature = "cassandra")]
use cassandra_protocol::compression::Compression;
use core::fmt;
Expand Down Expand Up @@ -128,5 +128,5 @@ pub trait CodecBuilder: Clone + Send {

fn new(direction: Direction, destination_name: String) -> Self;

fn websocket_subprotocol(&self) -> &'static str;
fn protocol(&self) -> MessageType;
}
4 changes: 2 additions & 2 deletions shotover/src/codec/opensearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ impl CodecBuilder for OpenSearchCodecBuilder {
)
}

fn websocket_subprotocol(&self) -> &'static str {
"opensearch"
fn protocol(&self) -> MessageType {
MessageType::OpenSearch
}
}

Expand Down
4 changes: 2 additions & 2 deletions shotover/src/codec/redis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ impl CodecBuilder for RedisCodecBuilder {
)
}

fn websocket_subprotocol(&self) -> &'static str {
"redis"
fn protocol(&self) -> MessageType {
MessageType::Redis
}
}

Expand Down
30 changes: 30 additions & 0 deletions shotover/src/frame/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,36 @@ pub enum MessageType {
OpenSearch,
}

impl MessageType {
pub fn is_inorder(&self) -> bool {
match self {
#[cfg(feature = "cassandra")]
MessageType::Cassandra => false,
#[cfg(feature = "redis")]
MessageType::Redis => true,
#[cfg(feature = "kafka")]
MessageType::Kafka => true,
#[cfg(feature = "opensearch")]
MessageType::OpenSearch => true,
MessageType::Dummy => false,
}
}

pub fn websocket_subprotocol(&self) -> &'static str {
match self {
#[cfg(feature = "cassandra")]
MessageType::Cassandra => "cql",
#[cfg(feature = "redis")]
MessageType::Redis => "redis",
#[cfg(feature = "kafka")]
MessageType::Kafka => "kafka",
#[cfg(feature = "opensearch")]
MessageType::OpenSearch => "opensearch",
MessageType::Dummy => "dummy",
}
}
}

impl From<&ProtocolType> for MessageType {
fn from(value: &ProtocolType) -> Self {
match value {
Expand Down
2 changes: 1 addition & 1 deletion shotover/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum Metadata {
OpenSearch,
}

#[derive(PartialEq)]
#[derive(Clone, PartialEq)]
pub enum ProtocolType {
#[cfg(feature = "cassandra")]
Cassandra { compression: Compression },
Expand Down
2 changes: 1 addition & 1 deletion shotover/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ impl<C: CodecBuilder + 'static> Handler<C> {

match transport {
Transport::WebSocket => {
let websocket_subprotocol = codec_builder.websocket_subprotocol();
let websocket_subprotocol = codec_builder.protocol().websocket_subprotocol();

if let Some(tls) = &self.tls {
let tls_stream = match tls.accept(stream).await {
Expand Down

0 comments on commit 53f417f

Please sign in to comment.