pub struct StreamSegment { /* private fields */ }Expand description
Builder for streaming segment metadata.
Manages session/segment IDs and auto-incrementing sequence numbers for real-time streaming patterns (voice, video, sensor streams).
The state transitions are easy to get subtly wrong, so they are worth
spelling out: chunk stamps the current (segment_id, seq)
and then auto-increments seq; next_segment bumps
segment_id and resets seq to 0; and flush advances to a
new segment and emits a chunk marked flush = true, fin = false (the
prior segment is discarded, not completed, so it intentionally never gets a
fin = true).
§Example
use dora_node_api::{
StreamSegment,
metadata::{FIN, FLUSH, SEGMENT_ID, SEQ, get_bool_param, get_integer_param},
};
let mut seg = StreamSegment::with_session_id("session-1".to_string());
// `chunk` stamps the current (segment, seq), then advances seq.
let first = seg.chunk(false);
assert_eq!(get_integer_param(&first, SEGMENT_ID), Some(0));
assert_eq!(get_integer_param(&first, SEQ), Some(0));
assert_eq!(get_bool_param(&first, FIN), Some(false));
let second = seg.chunk(true); // mark this chunk as the end of the segment
assert_eq!(get_integer_param(&second, SEQ), Some(1)); // seq auto-incremented
assert_eq!(get_bool_param(&second, FIN), Some(true));
// `flush` starts a new segment (seq reset to 0) and marks flush=true,
// fin=false: the old queued data is discarded, not completed.
let flushed = seg.flush();
assert_eq!(get_integer_param(&flushed, SEGMENT_ID), Some(1));
assert_eq!(get_integer_param(&flushed, SEQ), Some(0));
assert_eq!(get_bool_param(&flushed, FLUSH), Some(true));
assert_eq!(get_bool_param(&flushed, FIN), Some(false));Implementations§
Source§impl StreamSegment
impl StreamSegment
Sourcepub fn with_session_id(session_id: String) -> Self
pub fn with_session_id(session_id: String) -> Self
Start a new session with an explicit session ID.
Sourcepub fn next_segment(&mut self) -> i64
pub fn next_segment(&mut self) -> i64
Advance to a new segment (resets seq to 0). Returns the new segment_id.
Sourcepub fn chunk(&mut self, fin: bool) -> MetadataParameters
pub fn chunk(&mut self, fin: bool) -> MetadataParameters
Build metadata parameters for a chunk. Auto-increments seq.
Sourcepub fn flush(&mut self) -> MetadataParameters
pub fn flush(&mut self) -> MetadataParameters
Build metadata for a flush message (new segment, discards older queued data).
Advances to a new segment, then emits a chunk with flush=true and
fin=false. The prior segment ends without a fin=true signal – this
is intentional for interruption semantics (the old data is being
discarded, not completed).
Note: flush discards all queued messages on the receiver’s input
regardless of session_id. Do not multiplex independent sessions on a
single DataId when using flush.
Sourcepub fn session_id(&self) -> &str
pub fn session_id(&self) -> &str
Returns the session ID.
Sourcepub fn segment_id(&self) -> i64
pub fn segment_id(&self) -> i64
Returns the current segment ID.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StreamSegment
impl RefUnwindSafe for StreamSegment
impl Send for StreamSegment
impl Sync for StreamSegment
impl Unpin for StreamSegment
impl UnsafeUnpin for StreamSegment
impl UnwindSafe for StreamSegment
Blanket Implementations§
Source§impl<Source> AccessAs for Source
impl<Source> AccessAs for Source
impl<T> Allocation for T
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request