Skip to content
Merged
Changes from 2 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
11 changes: 10 additions & 1 deletion src/sinks/websocket/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,20 +196,26 @@ pub struct WebSocketSink {
connector: WebSocketConnector,
ping_interval: Option<NonZeroU64>,
ping_timeout: Option<NonZeroU64>,
encode_as_binary: bool,
}

impl WebSocketSink {
pub fn new(config: &WebSocketSinkConfig, connector: WebSocketConnector) -> crate::Result<Self> {
let transformer = config.encoding.transformer();
let serializer = config.encoding.build()?;
let encoder = Encoder::<()>::new(serializer);
let encode_as_binary = match config.encoding.config() {
codecs::encoding::SerializerConfig::RawMessage => true,
_ => false,
};
Comment thread
neuronull marked this conversation as resolved.
Outdated

Ok(Self {
transformer,
encoder,
connector,
ping_interval: config.ping_interval,
ping_timeout: config.ping_timeout,
encode_as_binary: encode_as_binary,
})
}

Expand Down Expand Up @@ -301,7 +307,10 @@ impl WebSocketSink {
Ok(()) => {
finalizers.update_status(EventStatus::Delivered);

let message = Message::text(String::from_utf8_lossy(&bytes));
let message = match self.encode_as_binary {
true => Message::binary(bytes),
false => Message::text(String::from_utf8_lossy(&bytes)),
};
Comment thread
neuronull marked this conversation as resolved.
Outdated
let message_len = message.len();

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