pub mod frame;
use crate::{BearerToken, StreamId, WriterId};
#[derive(Clone, Debug)]
pub struct ReadStreamOptions {
pub stream_id: StreamId,
pub start: Option<ReadStart>,
pub count: Option<u64>,
pub until: Option<u64>,
pub bearer_token: Option<BearerToken>,
}
impl ReadStreamOptions {
pub fn new(stream_id: StreamId) -> Self {
Self {
stream_id,
start: None,
count: None,
until: None,
bearer_token: None,
}
}
pub fn with_bearer_token(mut self, bearer_token: impl Into<BearerToken>) -> Self {
self.bearer_token = Some(bearer_token.into());
self
}
pub fn with_stream_token(self, token: &BearerToken) -> Self {
self.with_bearer_token(token.clone())
}
pub(crate) fn query_pairs(&self) -> Vec<(&'static str, String)> {
let mut pairs = Vec::new();
match self.start {
None => {}
Some(ReadStart::SeqNum(seq_num)) => pairs.push(("seq_num", seq_num.to_string())),
Some(ReadStart::TimestampMs(timestamp)) => {
pairs.push(("timestamp", timestamp.to_string()));
}
Some(ReadStart::TailOffset(tail_offset)) => {
pairs.push(("tail_offset", tail_offset.to_string()));
}
}
if let Some(count) = self.count {
pairs.push(("count", count.to_string()));
}
if let Some(until) = self.until {
pairs.push(("until", until.to_string()));
}
pairs
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ReadStart {
SeqNum(u64),
TimestampMs(u64),
TailOffset(u64),
}
#[derive(Clone, Debug)]
pub struct WriteStreamOptions {
pub stream_id: StreamId,
pub writer_id: WriterId,
pub bearer_token: BearerToken,
}
impl WriteStreamOptions {
pub fn new(
stream_id: StreamId,
writer_id: WriterId,
bearer_token: impl Into<BearerToken>,
) -> Self {
Self {
stream_id,
writer_id,
bearer_token: bearer_token.into(),
}
}
pub fn with_stream_token(
stream_id: StreamId,
writer_id: WriterId,
token: &BearerToken,
) -> Self {
Self::new(stream_id, writer_id, token.clone())
}
}