pub mod frame;
use crate::{LinkSecret, 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 link_secret: Option<LinkSecret>,
}
impl ReadStreamOptions {
pub fn new(stream_id: StreamId) -> Self {
Self {
stream_id,
start: None,
count: None,
until: None,
link_secret: None,
}
}
pub fn with_link_secret(mut self, link_secret: impl Into<LinkSecret>) -> Self {
self.link_secret = Some(link_secret.into());
self
}
pub fn with_stream_link(self, link: &LinkSecret) -> Self {
self.with_link_secret(link.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 link_secret: LinkSecret,
}
impl WriteStreamOptions {
pub fn new(
stream_id: StreamId,
writer_id: WriterId,
link_secret: impl Into<LinkSecret>,
) -> Self {
Self {
stream_id,
writer_id,
link_secret: link_secret.into(),
}
}
pub fn with_stream_link(stream_id: StreamId, writer_id: WriterId, link: &LinkSecret) -> Self {
Self::new(stream_id, writer_id, link.clone())
}
}