pub struct TokenNativeCodec { /* private fields */ }Expand description
Token-native compression codec
Compresses text by converting to token IDs and encoding with VarInt.
Implementations§
Source§impl TokenNativeCodec
impl TokenNativeCodec
Sourcepub fn new(encoding: Encoding) -> Self
pub fn new(encoding: Encoding) -> Self
Create a new token-native codec with the specified encoding
Sourcepub fn compress(&self, text: &str) -> Result<CompressionResult>
pub fn compress(&self, text: &str) -> Result<CompressionResult>
Compress text to token-native wire format
Sourcepub fn decompress(&self, wire: &str) -> Result<String>
pub fn decompress(&self, wire: &str) -> Result<String>
Decompress from token-native wire format
Sourcepub fn compress_raw(&self, text: &str) -> Vec<u8> ⓘ
pub fn compress_raw(&self, text: &str) -> Vec<u8> ⓘ
Compress and return raw bytes (no wire format prefix)
Sourcepub fn decompress_raw(&self, bytes: &[u8]) -> Result<String>
pub fn decompress_raw(&self, bytes: &[u8]) -> Result<String>
Decompress from raw bytes
Sourcepub fn compress_binary(&self, text: &str) -> Vec<u8> ⓘ
pub fn compress_binary(&self, text: &str) -> Vec<u8> ⓘ
Compress to binary wire format (tokenizer ID + raw bytes)
Binary format: <tokenizer_byte><varint_tokens>
- Byte 0: Tokenizer ID (0=cl100k, 1=o200k, 2=llama)
- Bytes 1+: VarInt-encoded token IDs
Use this for binary-safe channels (WebSocket binary, QUIC, etc.) to achieve maximum compression (~50% of original).
Sourcepub fn decompress_binary(bytes: &[u8]) -> Result<String>
pub fn decompress_binary(bytes: &[u8]) -> Result<String>
Decompress from binary wire format
Trait Implementations§
Source§impl Clone for TokenNativeCodec
impl Clone for TokenNativeCodec
Source§fn clone(&self) -> TokenNativeCodec
fn clone(&self) -> TokenNativeCodec
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TokenNativeCodec
impl Debug for TokenNativeCodec
Source§impl Default for TokenNativeCodec
impl Default for TokenNativeCodec
impl Copy for TokenNativeCodec
Auto Trait Implementations§
impl Freeze for TokenNativeCodec
impl RefUnwindSafe for TokenNativeCodec
impl Send for TokenNativeCodec
impl Sync for TokenNativeCodec
impl Unpin for TokenNativeCodec
impl UnwindSafe for TokenNativeCodec
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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