Skip to content

Commit

Permalink
Make some stuff pub
Browse files Browse the repository at this point in the history
  • Loading branch information
jordy25519 committed Nov 7, 2024
1 parent d2c8061 commit 2a6e7a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/protocol/frame/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ impl Frame {
/// Create a new compressed data frame.
#[inline]
#[cfg(feature = "deflate")]
pub(crate) fn compressed_message(data: Vec<u8>, opcode: OpCode, is_final: bool) -> Frame {
pub fn compressed_message(data: Vec<u8>, opcode: OpCode, is_final: bool) -> Frame {
debug_assert!(matches!(opcode, OpCode::Data(_)), "Invalid opcode for data frame.");

Frame {
Expand Down
13 changes: 13 additions & 0 deletions src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,11 @@ impl<Stream: Read + Write> WebSocket<Stream> {
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
Expand Down Expand Up @@ -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<Stream>(&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)?;
Expand Down

0 comments on commit 2a6e7a6

Please sign in to comment.