pub struct StreamingCodec { /* private fields */ }Expand description
Streaming codec for SSE compression
Maintains state across chunks for optimal compression and accumulates content for final aggregation.
Implementations§
Source§impl StreamingCodec
impl StreamingCodec
Sourcepub fn with_mode(mode: StreamingMode) -> Self
pub fn with_mode(mode: StreamingMode) -> Self
Create codec with specific mode
Sourcepub fn token_native(encoding: Encoding) -> Self
pub fn token_native(encoding: Encoding) -> Self
Create codec with TokenNative mode and specific encoding
Sourcepub fn hybrid(encoding: Encoding) -> Self
pub fn hybrid(encoding: Encoding) -> Self
Create codec with Hybrid mode (abbreviation + final TokenNative)
Sourcepub fn passthrough() -> Self
pub fn passthrough() -> Self
Create codec with compression disabled (passthrough)
Sourcepub fn mode(&self) -> StreamingMode
pub fn mode(&self) -> StreamingMode
Get current streaming mode
Sourcepub fn parse_sse_line(&self, line: &str) -> Option<SseEvent>
pub fn parse_sse_line(&self, line: &str) -> Option<SseEvent>
Parse an SSE line into an event
Sourcepub fn process_chunk(&mut self, chunk: &[u8]) -> Result<Vec<Bytes>>
pub fn process_chunk(&mut self, chunk: &[u8]) -> Result<Vec<Bytes>>
Process a raw SSE chunk (may contain multiple events)
Sourcepub fn accumulated_content(&self) -> &str
pub fn accumulated_content(&self) -> &str
Get accumulated content from all chunks
Sourcepub fn finalize_token_native(&self) -> Result<CompressionResult>
pub fn finalize_token_native(&self) -> Result<CompressionResult>
Finalize streaming with TokenNative compression
For Hybrid mode, this compresses the full accumulated content using TokenNative for maximum compression.
Returns the compression result with statistics.
Sourcepub fn finalize_raw(&self) -> Vec<u8> ⓘ
pub fn finalize_raw(&self) -> Vec<u8> ⓘ
Finalize with raw bytes (no base64 overhead)
For binary-safe channels, returns raw VarInt-encoded token IDs.
Sourcepub fn finalize_m2m(&self, response_json: &str) -> Result<String>
pub fn finalize_m2m(&self, response_json: &str) -> Result<String>
Finalize streaming with M2M frame encoding
Wraps the accumulated content in an M2M response frame with:
- Response headers (model, token counts if available)
- Brotli compression for large content
- CRC32 integrity check
This is useful when you want to store or transmit the final accumulated response with full M2M wire format benefits.
§Arguments
response_json- Complete response JSON to wrap (should include the accumulated content)
§Returns
M2M-encoded response as a string (base64 format for text transport)
Sourcepub fn finalize_m2m_binary(&self, response_json: &str) -> Result<Vec<u8>>
pub fn finalize_m2m_binary(&self, response_json: &str) -> Result<Vec<u8>>
Finalize streaming with M2M frame encoding (binary)
Same as finalize_m2m but returns raw bytes instead of base64.
Use this for binary-safe transport channels.
Sourcepub fn stats(&self) -> StreamingStats
pub fn stats(&self) -> StreamingStats
Get compression statistics
Trait Implementations§
Source§impl Debug for StreamingCodec
impl Debug for StreamingCodec
Auto Trait Implementations§
impl Freeze for StreamingCodec
impl RefUnwindSafe for StreamingCodec
impl Send for StreamingCodec
impl Sync for StreamingCodec
impl Unpin for StreamingCodec
impl UnwindSafe for StreamingCodec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more