use crate::{
SpopFrame,
actions::{Action, VarScope},
frame::{FrameFlags, FramePayload, FrameType, Metadata},
types::TypedData,
};
use std::borrow::Cow;
#[derive(Debug, Clone)]
pub struct Ack {
pub stream_id: u64,
pub frame_id: u64,
pub actions: Vec<Action>,
}
impl Ack {
#[must_use]
pub const fn new(stream_id: u64, frame_id: u64) -> Self {
Self {
stream_id,
frame_id,
actions: Vec::new(),
}
}
#[must_use]
pub fn set_var(mut self, scope: VarScope, name: &str, value: impl Into<TypedData>) -> Self {
self.actions.push(Action::SetVar {
scope,
name: name.to_string(),
value: value.into(),
});
self
}
#[must_use]
pub fn unset_var(mut self, scope: VarScope, name: &str) -> Self {
self.actions.push(Action::UnSetVar {
scope,
name: name.to_string(),
});
self
}
}
impl SpopFrame for Ack {
fn frame_type(&self) -> &FrameType {
&FrameType::Ack
}
fn metadata(&self) -> Cow<'_, Metadata> {
Cow::Owned(Metadata {
flags: FrameFlags::new(true, false), stream_id: self.stream_id,
frame_id: self.frame_id,
})
}
fn payload(&self) -> FramePayload<'_> {
FramePayload::ListOfActions(&self.actions)
}
}