From 2a6e7a62b3651ad520131982e28dc085c4c1b0f8 Mon Sep 17 00:00:00 2001 From: jordy25519 Date: Thu, 7 Nov 2024 18:23:34 +0800 Subject: [PATCH] Make some stuff pub --- src/protocol/frame/frame.rs | 2 +- src/protocol/mod.rs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/protocol/frame/frame.rs b/src/protocol/frame/frame.rs index 54e23ae8..e9224d3e 100644 --- a/src/protocol/frame/frame.rs +++ b/src/protocol/frame/frame.rs @@ -318,7 +318,7 @@ impl Frame { /// Create a new compressed data frame. #[inline] #[cfg(feature = "deflate")] - pub(crate) fn compressed_message(data: Vec, opcode: OpCode, is_final: bool) -> Frame { + pub fn compressed_message(data: Vec, opcode: OpCode, is_final: bool) -> Frame { debug_assert!(matches!(opcode, OpCode::Data(_)), "Invalid opcode for data frame."); Frame { diff --git a/src/protocol/mod.rs b/src/protocol/mod.rs index e30c3730..541af7dd 100644 --- a/src/protocol/mod.rs +++ b/src/protocol/mod.rs @@ -342,6 +342,11 @@ impl WebSocket { self.context.write(&mut self.socket, message) } + /// Like `write` but accepts a `Frame` + pub fn write_frame(&mut self, frame: Frame) -> Result<()> { + self.context.write_frame(&mut self.socket, frame) + } + /// Flush writes. /// /// Ensures all messages previously passed to [`write`](Self::write) and automatic @@ -565,6 +570,14 @@ impl WebSocketContext { Message::Frame(f) => f, }; + self.write_frame(stream, frame) + } + + /// Write a frame to the provided stream. + pub fn write_frame(&mut self, stream: &mut Stream, frame: Frame) -> Result<()> + where + Stream: Read + Write, + { let should_flush = self._write(stream, Some(frame))?; if should_flush { self.flush(stream)?;