Skip to main content

Ctx

Struct Ctx 

Source
pub struct Ctx<'a> { /* private fields */ }
Expand description

Handed to a plugin for each chunk.

A stage must say what happens to the chunk: pass_through forwards it untouched, forward emits different bytes, and doing neither drops it. Passthrough is the fast path and costs nothing (the next stage receives the same slice).

Several calls to forward in one turn emit one unit, not several: the bytes concatenate and are delivered together. boundary is how a stage says otherwise.

Implementations§

Source§

impl<'a> Ctx<'a>

Source

pub fn new( meta: &'a PipelineMeta, stage: &'a str, input: &'a [u8], emission: &'a mut Emission, sink: &'a mut dyn EffectSink, ) -> Self

Source

pub fn stage(&self) -> &str

This stage’s display name, as it appears in logs.

Source

pub fn meta(&self) -> &PipelineMeta

Source

pub fn direction(&self) -> Direction

Source

pub fn input(&self) -> &[u8]

The chunk this call was given. Empty during Plugin::on_eof.

Source

pub fn pass_through(&mut self)

Forward the input unchanged, without copying it.

Source

pub fn forward(&mut self, bytes: &[u8])

Emit bytes downstream. Performs a copy. Use pass_through when the bytes are the input.

Appends: calling this twice emits both, in order, as one unit. Call boundary between them to emit two.

Source

pub fn drop_chunk(&mut self)

Explicitly swallow the chunk. Emitting nothing does the same thing; this exists so a filter can state the intent.

Source

pub fn boundary(&mut self)

End the current unit. What was forwarded since the last boundary is delivered on its own: one write at a byte sink, one message at a datagram sink, one parcel across a detached boundary, and one on_bytes call at every stage below.

Only worth calling when those splits are the point, as with a stage cutting a stream into fixed-size records. Framing is not free: each stage below is then called once per unit rather than once per chunk, so a stage that emits many small units is asking the rest of the segment to run many times. A stage that only rewrites bytes should leave the framing it was given alone and say nothing.

The trailing unit does not need one: whatever is forwarded after the last boundary is closed automatically, so no bytes can be lost by forgetting.

Ignored when nothing has been forwarded since the last call, so a stage cannot emit an empty unit by accident.

Source

pub fn rearm(&mut self)

Restart this stage’s tick schedule: the next on_tick falls a full interval from now rather than wherever the existing cadence happens to land.

A stage cannot read a clock, so it cannot measure how long it has been holding something. What it can do is say when the waiting started, and this is how. A stage that begins accumulating calls this, and its next tick then means “an interval since you asked” rather than “an interval since some earlier moment you know nothing about”.

Without it, tick_interval is a cadence rather than a delay: a tick that came due while bytes were flowing fires at the next opportunity, which can be immediately after the bytes it is about arrived.

Cheap to call, and harmless to call often: it sets a flag the host reads once at the end of the call. Ignored for a stage that asked for no ticks.

Source

pub fn side_write(&mut self, channel: ChannelId, bytes: &[u8])

Stage bytes for a side channel obtained from BuildCtx::open_channel.

Source

pub fn log(&mut self, level: LogLevel, message: &str)

Source

pub fn pace(&mut self, delay: Duration)

Ask the host to wait delay before reading upstream again.

Applied after this call returns and after whatever was emitted has been written, so the bytes in hand are never held hostage by the wait. On a socket this is real backpressure: the read stops, the receive buffer fills, the window closes and the peer slows down. Nothing is buffered on this side.

Source

pub fn halt(&mut self, reason: &str)

Ask the host to stop reading upstream, as if it had reached end of stream. reason is logged against this stage.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Ctx<'a>

§

impl<'a> !Send for Ctx<'a>

§

impl<'a> !Sync for Ctx<'a>

§

impl<'a> !UnwindSafe for Ctx<'a>

§

impl<'a> Freeze for Ctx<'a>

§

impl<'a> Unpin for Ctx<'a>

§

impl<'a> UnsafeUnpin for Ctx<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.