Skip to main content

CodecRegistry

Struct CodecRegistry 

Source
pub struct CodecRegistry { /* private fields */ }
Expand description

codec dispatch レジストリ。Arc 越しに S4Service / 複数タスクから共有する想定。

Implementations§

Source§

impl CodecRegistry

Source

pub fn new(default: CodecKind) -> Self

default で指定した codec が PUT 時の codec として使われる (dispatcher が別 kind を選んだ場合は、その kind が登録されていれば優先)。

Source

pub fn register(&mut self, codec: Arc<dyn Codec>) -> &mut Self

codec を登録。同じ kind を 2 度登録すると後勝ち。

Source

pub fn with(self, codec: Arc<dyn Codec>) -> Self

register の chain 用 builder

Source

pub fn kinds(&self) -> impl Iterator<Item = CodecKind> + '_

登録済 kind 一覧

Source

pub fn default_kind(&self) -> CodecKind

default kind

Source

pub async fn compress( &self, input: Bytes, kind: CodecKind, ) -> Result<(Bytes, ChunkManifest), CodecError>

指定 kind の codec で compress

Source

pub async fn decompress( &self, input: Bytes, manifest: &ChunkManifest, ) -> Result<Bytes, CodecError>

manifest が指す codec で decompress (本命の dispatch path)

Source

pub async fn compress_with_telemetry( &self, input: Bytes, kind: CodecKind, ) -> (Result<(Bytes, ChunkManifest), CodecError>, CompressTelemetry)

v0.8 #55: same as Self::compress but additionally returns a CompressTelemetry describing the operation (codec name, input/output size, GPU wall-clock seconds for GPU codecs, OOM flag on failure). Lets s4-server stamp Prometheus metrics (s4_gpu_compress_seconds, s4_gpu_throughput_bytes_per_sec, s4_gpu_oom_total) without s4-codec itself depending on the metrics crate (callback / return-value pattern, keeps the codec dep tree slim).

On Ok, telemetry has the measured bytes_in / bytes_out and gpu_seconds = Some(secs) for GPU kinds, None for CPU. On Err, telemetry has bytes_in = input.len() as u64 and bytes_out = 0, with oom = true iff the error string matches the OOM heuristic (crate::looks_like_oom).

Source

pub async fn decompress_with_telemetry( &self, input: Bytes, manifest: &ChunkManifest, ) -> (Result<Bytes, CodecError>, CompressTelemetry)

v0.8 #55: telemetry-returning decompress. Mirrors Self::compress_with_telemetry for the GET / decompress side so operators can dashboard GPU decompress p99 separately from the compress histogram.

Trait Implementations§

Source§

impl Debug for CodecRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.