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

CodecBuilder::protocol #1491

Merged
merged 1 commit into from
Feb 21, 2024
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
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/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
Loading