pub struct StreamingEncoder { /* private fields */ }Expand description
Streaming encoder with a selectable sink: in-memory buffer (default) or caller-supplied JS callback.
Lifecycle:
new(meta, hash?, on_bytes?)— writes preamble + header metadata frame. In buffered mode these bytes accumulate internally; in streaming mode they flow toon_bytesimmediately.- Zero or more
write_preceder(meta)/write_object(desc, data)/write_object_pre_encoded(desc, data)calls. finish()writes the footer + postamble. In buffered mode returns the completeUint8Array; in streaming mode returns an emptyUint8Array(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
impl StreamingEncoder
Sourcepub 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>
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.
Sourcepub fn write_preceder(&mut self, metadata_js: JsValue) -> Result<(), JsValue>
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.
Sourcepub fn write_object(
&mut self,
descriptor_js: JsValue,
data: JsValue,
) -> Result<(), JsValue>
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.
Sourcepub fn write_object_pre_encoded(
&mut self,
descriptor_js: JsValue,
data: JsValue,
) -> Result<(), JsValue>
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.
Sourcepub fn object_count(&self) -> Result<usize, JsValue>
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.
Sourcepub fn bytes_written(&self) -> Result<f64, JsValue>
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.
Sourcepub fn finish(&mut self) -> Result<Uint8Array, JsValue>
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
impl From<StreamingEncoder> for JsValue
Source§fn from(value: StreamingEncoder) -> Self
fn from(value: StreamingEncoder) -> Self
Source§impl FromWasmAbi for StreamingEncoder
impl FromWasmAbi for StreamingEncoder
Source§impl IntoWasmAbi for StreamingEncoder
impl IntoWasmAbi for StreamingEncoder
Source§impl OptionFromWasmAbi for StreamingEncoder
impl OptionFromWasmAbi for StreamingEncoder
Source§impl OptionIntoWasmAbi for StreamingEncoder
impl OptionIntoWasmAbi for StreamingEncoder
Source§impl RefFromWasmAbi for StreamingEncoder
impl RefFromWasmAbi for StreamingEncoder
Source§type Anchor = RcRef<StreamingEncoder>
type Anchor = RcRef<StreamingEncoder>
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§impl RefMutFromWasmAbi for StreamingEncoder
impl RefMutFromWasmAbi for StreamingEncoder
Source§impl TryFromJsValue for StreamingEncoder
impl TryFromJsValue for StreamingEncoder
Source§impl VectorFromWasmAbi for StreamingEncoder
impl VectorFromWasmAbi for StreamingEncoder
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[StreamingEncoder]>
Source§impl VectorIntoWasmAbi for StreamingEncoder
impl VectorIntoWasmAbi for StreamingEncoder
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[StreamingEncoder]>) -> Self::Abi
Source§impl WasmDescribeVector for StreamingEncoder
impl WasmDescribeVector for StreamingEncoder
impl SupportsConstructor for StreamingEncoder
impl SupportsInstanceProperty for StreamingEncoder
impl SupportsStaticProperty for StreamingEncoder
Auto Trait Implementations§
impl Freeze for StreamingEncoder
impl RefUnwindSafe for StreamingEncoder
impl Send for StreamingEncoder
impl Sync for StreamingEncoder
impl Unpin for StreamingEncoder
impl UnsafeUnpin for StreamingEncoder
impl UnwindSafe for StreamingEncoder
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
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> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.