Skip to main content

Decoder

Trait Decoder 

Source
pub trait Decoder<'id, Op: Operation, Frame = WireFrame> {
    type Event;

    // Required methods
    fn classify(&self, frame: Frame) -> WireEvent<Self::Event>;
    fn decode(
        &mut self,
        event: Self::Event,
        out: Out<'id, Op>,
    ) -> Result<Flow, ProviderError>;

    // Provided method
    fn eof(&mut self, out: Out<'id, Op>) -> Result<Flow, ProviderError> { ... }
}
Expand description

Synchronous state machine for one reply. It classifies frames and decodes known events into the reply’s writer, without transport access and without being told how the reply arrives. HTTP wires read WireFrames; other transports name their own frame type.

Required Associated Types§

Source

type Event

The wire’s typed event, produced by this decoder’s classifier.

Required Methods§

Source

fn classify(&self, frame: Frame) -> WireEvent<Self::Event>

Decode and classify one frame. A JSON wire MUST delegate to a classifier in crate::providers::internal::wire, so the decode-then-validate policy is not re-derived per provider.

Source

fn decode( &mut self, event: Self::Event, out: Out<'id, Op>, ) -> Result<Flow, ProviderError>

Write one Known event into the reply. An error ends the reply with it.

Provided Methods§

Source

fn eof(&mut self, out: Out<'id, Op>) -> Result<Flow, ProviderError>

The frames ran out without an end. A decoder that already saw the provider’s end, in a form the provider sends before its last frame, ends the reply here; otherwise the reply is truncated.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<'id, Op: Operation, Event> Decoder<'id, Op> for DocumentDecoder<Op, Event>

Source§

type Event = Event

Source§

impl<'id, Op> Decoder<'id, Op> for Json
where Op: Operation<Emit = Free>, Op::End: DeserializeOwned,

Source§

type Event = (<Op as Operation>::End, Value)

Source§

impl<'id> Decoder<'id, AudioGeneration> for rig_core::providers::gemini::audio_generation::SpeechDecoder

Available on crate feature audio only.
Source§

impl<'id> Decoder<'id, AudioGeneration> for rig_core::providers::openai::wire::SpeechDecoder

Available on crate feature audio only.
Source§

impl<'id> Decoder<'id, Completion, GenerateContentChunk> for GenerateContentDecoder

A transport that delivers each reply message as its REST chunk, such as an SDK’s reply transcoded once, hands the decoder the chunk itself.

Source§

impl<'id> Decoder<'id, Completion, MockFrame> for MockDecoder<'id>

Available on crate feature test-utils only.
Source§

impl<'id> Decoder<'id, Completion> for rig_core::providers::cohere::streaming::ChatDecoder

Source§

impl<'id> Decoder<'id, Completion> for rig_core::providers::ollama::streaming::ChatDecoder

Source§

impl<'id> Decoder<'id, Completion> for CohereDecoder

Source§

impl<'id> Decoder<'id, Completion> for GenerateContentDecoder

Source§

impl<'id> Decoder<'id, Completion> for InteractionsDecoder

EOF without interaction.completed is truncation, not successful completion, so the decoder has nothing to add at the end of the reply.

Source§

impl<'id> Decoder<'id, Completion> for MessagesDecoder

Source§

impl<'id> Decoder<'id, Completion> for OpenAiDecoder

Source§

impl<'id> Decoder<'id, Completion> for ResponsesDecoder

Source§

impl<'id> Decoder<'id, ContextCache> for CachedContentsDecoder

Source§

impl<'id> Decoder<'id, Embedding> for EmbeddingsDecoder

Source§

impl<'id> Decoder<'id, ImageGeneration> for ImagesDecoder

Available on crate feature image only.
Source§

impl<'id> Decoder<'id, Verify> for VerifyDecoder

Source§

impl<'id> Decoder<'id, Verify> for VerifyKeyDecoder

Source§

impl<'id> Decoder<'id, VoiceCloning> for VoiceClonesDecoder

Available on crate feature audio only.