Skip to content

Commit

Permalink
fix: extract the logic into a function
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongchen committed Jul 25, 2023
1 parent 2628ea1 commit 9ca2e70
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/sinks/websocket/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ use crate::{
tls::{MaybeTlsSettings, MaybeTlsStream, TlsError},
};

use codecs::encoding::Serializer::{RawMessage, Avro, Native, Csv, Logfmt, Gelf, Json, Text, NativeJson};


#[derive(Debug, Snafu)]
#[snafu(visibility(pub))]
Expand Down Expand Up @@ -239,6 +237,16 @@ impl WebSocketSink {
Ok(())
}

fn should_encode_as_binary(serializer: &Serializer) -> bool {
use codecs::encoding::Serializer::{RawMessage, Avro, Native, Csv,
Logfmt, Gelf, Json, Text, NativeJson};

match serializer {
Raw(_) | Avro(_) | Native(_) => true,
Csv(_) | Logfmt(_) | Gelf(_) | Json(_) | Text(_) | NativeJson(_) => false,
}
}

async fn handle_events<I, WS, O>(
&mut self,
input: &mut I,
Expand All @@ -264,11 +272,7 @@ impl WebSocketSink {

let bytes_sent = register!(BytesSent::from(Protocol("websocket".into())));
let events_sent = register!(EventsSent::from(Output(None)));
let encode_as_binary = match self.encoder.serializer() {
RawMessage(_) | Avro(_) | Native(_) => true,
Csv(_) | Logfmt(_) | Gelf(_) | Json(_) | Text(_) | NativeJson(_) => false,
};

let encode_as_binary = should_encode_as_binary(self.encoder.serializer());

loop {
let result = tokio::select! {
Expand Down

0 comments on commit 9ca2e70

Please sign in to comment.