1use crate::{
2 SpopFrame,
3 actions::{Action, VarScope},
4 frame::{FrameFlags, FramePayload, FrameType, Metadata},
5 types::TypedData,
6};
7
8#[derive(Debug, Clone)]
21pub struct Ack {
22 pub stream_id: u64,
23 pub frame_id: u64,
24 pub actions: Vec<Action>,
25}
26
27impl Ack {
28 pub const fn new(stream_id: u64, frame_id: u64) -> Self {
30 Self {
31 stream_id,
32 frame_id,
33 actions: Vec::new(),
34 }
35 }
36
37 pub fn set_var(mut self, scope: VarScope, name: &str, value: impl Into<TypedData>) -> Self {
39 self.actions.push(Action::SetVar {
40 scope,
41 name: name.to_string(),
42 value: value.into(),
43 });
44 self
45 }
46
47 pub fn unset_var(mut self, scope: VarScope, name: &str) -> Self {
49 self.actions.push(Action::UnSetVar {
50 scope,
51 name: name.to_string(),
52 });
53 self
54 }
55}
56
57impl SpopFrame for Ack {
59 fn frame_type(&self) -> &FrameType {
60 &FrameType::Ack
61 }
62
63 fn metadata(&self) -> Metadata {
64 Metadata {
65 flags: FrameFlags::new(true, false), stream_id: self.stream_id,
67 frame_id: self.frame_id,
68 }
69 }
70
71 fn payload(&self) -> FramePayload {
72 FramePayload::ListOfActions(self.actions.clone())
73 }
74}