Skip to main content

StreamingEncoder

Struct StreamingEncoder 

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

Streaming encoder with a selectable sink: in-memory buffer (default) or caller-supplied JS callback.

Lifecycle:

  1. new(meta, hash?, on_bytes?) — writes preamble + header metadata frame. In buffered mode these bytes accumulate internally; in streaming mode they flow to on_bytes immediately.
  2. Zero or more write_preceder(meta) / write_object(desc, data) / write_object_pre_encoded(desc, data) calls.
  3. finish() writes the footer + postamble. In buffered mode returns the complete Uint8Array; in streaming mode returns an empty Uint8Array (the callback has seen every byte).

After finish() the encoder is closed — every further method call throws “already finished”. Callers must still invoke the wasm-bindgen free() method when done with the handle.

Implementations§

Source§

impl StreamingEncoder

Source

pub fn new( metadata_js: JsValue, hash: Option<bool>, on_bytes: Option<Function>, allow_nan: Option<bool>, allow_inf: Option<bool>, nan_mask_method: Option<String>, pos_inf_mask_method: Option<String>, neg_inf_mask_method: Option<String>, small_mask_threshold_bytes: Option<usize>, ) -> Result<StreamingEncoder, JsValue>

Begin a new streaming message.

@param metadata_js - GlobalMetadata (JS object). Must contain version; base may carry per-object entries; _reserved_ is rejected (library-managed). @param hash - When true (default), xxh3 hashes are computed per object and stored in the footer hash frame. When false, hashing is disabled entirely. @param on_bytes - Optional synchronous callback invoked with each chunk of wire-format bytes the encoder produces. When present, no internal buffering is performed and finish() returns an empty Uint8Array. When absent, the encoder buffers to an internal Vec<u8> and finish() returns the complete message.

Source

pub fn write_preceder(&mut self, metadata_js: JsValue) -> Result<(), JsValue>

Write a PrecederMetadata frame for the next data object.

The provided object is merged into a GlobalMetadata with a single-entry base array. Must be followed by exactly one write_object / write_object_pre_encoded call before another write_preceder or finish.

Source

pub fn write_object( &mut self, descriptor_js: JsValue, data: JsValue, ) -> Result<(), JsValue>

Encode and write a single data object.

@param descriptor_js - DataObjectDescriptor as a plain JS object. @param data - Raw native-endian payload as any TypedArray.

Source

pub fn write_object_pre_encoded( &mut self, descriptor_js: JsValue, data: JsValue, ) -> Result<(), JsValue>

Write a pre-encoded data object directly (no pipeline).

data must already be encoded according to the descriptor’s encoding / filter / compression. The library does not run the pipeline — it validates descriptor structure and the szip block offsets (if any) and writes bytes verbatim. The hash is recomputed from these bytes if the encoder was constructed with hash: true.

Source

pub fn object_count(&self) -> Result<usize, JsValue>

Number of data objects written so far. Zero after new(), increments on every successful write_object / write_object_pre_encoded.

Source

pub fn bytes_written(&self) -> Result<f64, JsValue>

Total bytes produced so far (preamble + header frames + all completed data-object frames). In buffered mode this equals the length of the internal buffer; in streaming mode it equals the sum of byte-lengths passed to the callback.

Returned as f64 because JS numbers are the lingua-franca for sizes on the wire boundary. Number.MAX_SAFE_INTEGER ≈ 9 PiB, which is well beyond any realistic Tensogram message.

Source

pub fn finish(&mut self) -> Result<Uint8Array, JsValue>

Finalise the encoder, writing footer frames + postamble.

In buffered mode returns the complete wire-format Uint8Array. In streaming mode the footer bytes flow through the callback and the return value is an empty Uint8Array (zero-length marker, not a failure — every byte has already been delivered).

After this call the encoder is closed — any further method call throws “already finished”. Callers must still invoke the wasm-bindgen free() method when done with the handle.

Trait Implementations§

Source§

impl From<StreamingEncoder> for JsValue

Source§

fn from(value: StreamingEncoder) -> Self

Converts to this type from the input type.
Source§

impl FromWasmAbi for StreamingEncoder

Source§

type Abi = u32

The Wasm ABI type that this converts from when coming back out from the ABI boundary.
Source§

unsafe fn from_abi(js: u32) -> Self

Recover a Self from Self::Abi. Read more
Source§

impl IntoWasmAbi for StreamingEncoder

Source§

type Abi = u32

The Wasm ABI type that this converts into when crossing the ABI boundary.
Source§

fn into_abi(self) -> u32

Convert self into Self::Abi so that it can be sent across the wasm ABI boundary.
Source§

impl LongRefFromWasmAbi for StreamingEncoder

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRef<StreamingEncoder>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn long_ref_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl OptionFromWasmAbi for StreamingEncoder

Source§

fn is_none(abi: &Self::Abi) -> bool

Tests whether the argument is a “none” instance. If so it will be deserialized as None, and otherwise it will be passed to FromWasmAbi.
Source§

impl OptionIntoWasmAbi for StreamingEncoder

Source§

fn none() -> Self::Abi

Returns an ABI instance indicating “none”, which JS will interpret as the None branch of this option. Read more
Source§

impl RefFromWasmAbi for StreamingEncoder

Source§

type Abi = u32

The Wasm ABI type references to Self are recovered from.
Source§

type Anchor = RcRef<StreamingEncoder>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don’t persist beyond one function call, and so that they remain anonymous.
Source§

unsafe fn ref_from_abi(js: Self::Abi) -> Self::Anchor

Recover a Self::Anchor from Self::Abi. Read more
Source§

impl RefMutFromWasmAbi for StreamingEncoder

Source§

type Abi = u32

Same as RefFromWasmAbi::Abi
Source§

type Anchor = RcRefMut<StreamingEncoder>

Same as RefFromWasmAbi::Anchor
Source§

unsafe fn ref_mut_from_abi(js: Self::Abi) -> Self::Anchor

Same as RefFromWasmAbi::ref_from_abi
Source§

impl TryFromJsValue for StreamingEncoder

Source§

fn try_from_js_value(value: JsValue) -> Result<Self, JsValue>

Performs the conversion.
Source§

fn try_from_js_value_ref(value: &JsValue) -> Option<Self>

Performs the conversion.
Source§

impl VectorFromWasmAbi for StreamingEncoder

Source§

impl VectorIntoWasmAbi for StreamingEncoder

Source§

impl WasmDescribe for StreamingEncoder

Source§

impl WasmDescribeVector for StreamingEncoder

Source§

impl SupportsConstructor for StreamingEncoder

Source§

impl SupportsInstanceProperty for StreamingEncoder

Source§

impl SupportsStaticProperty for StreamingEncoder

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> ReturnWasmAbi for T
where T: IntoWasmAbi,

Source§

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi
Source§

fn return_abi(self) -> <T as ReturnWasmAbi>::Abi

Same as IntoWasmAbi::into_abi, except that it may throw and never return in the case of Err.
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.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more