Skip to content
Merged
Changes from 7 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
18 changes: 17 additions & 1 deletion src/sinks/websocket/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,16 @@ impl WebSocketSink {
Ok(())
}

fn should_encode_as_binary(&self) -> bool {
Comment thread
neuronull marked this conversation as resolved.
Outdated
use codecs::encoding::Serializer::{RawMessage, Avro, Native, Csv,
Logfmt, Gelf, Json, Text, NativeJson};

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

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

let bytes_sent = register!(BytesSent::from(Protocol("websocket".into())));
let events_sent = register!(EventsSent::from(Output(None)));
let encode_as_binary = self.should_encode_as_binary();

loop {
let result = tokio::select! {
Expand Down Expand Up @@ -301,7 +312,12 @@ impl WebSocketSink {
Ok(()) => {
finalizers.update_status(EventStatus::Delivered);

let message = Message::text(String::from_utf8_lossy(&bytes));
let message = if encode_as_binary {
Message::binary(bytes)
}
else {
Message::text(String::from_utf8_lossy(&bytes))
};
let message_len = message.len();

ws_sink.send(message).await.map(|_| {
Expand Down