rabbitmq_stream_protocol/commands/
publish_confirm.rs1use std::io::Write;
2
3use crate::{
4 codec::{Decoder, Encoder},
5 error::{DecodeError, EncodeError},
6 protocol::commands::COMMAND_PUBLISH_CONFIRM,
7};
8
9use super::Command;
10
11#[cfg_attr(test, derive(fake::Dummy))]
12#[derive(PartialEq, Eq, Debug)]
13pub struct PublishConfirm {
14 pub publisher_id: u8,
15 pub publishing_ids: Vec<u64>,
16}
17
18impl PublishConfirm {
19 pub fn new(publisher_id: u8, publishing_ids: Vec<u64>) -> Self {
20 Self {
21 publisher_id,
22 publishing_ids,
23 }
24 }
25}
26
27impl Encoder for PublishConfirm {
28 fn encode(&self, writer: &mut impl Write) -> Result<(), EncodeError> {
29 self.publisher_id.encode(writer)?;
30 self.publishing_ids.encode(writer)?;
31 Ok(())
32 }
33
34 fn encoded_size(&self) -> u32 {
35 self.publisher_id.encoded_size() + self.publishing_ids.encoded_size()
36 }
37}
38
39impl Command for PublishConfirm {
40 fn key(&self) -> u16 {
41 COMMAND_PUBLISH_CONFIRM
42 }
43}
44impl Decoder for PublishConfirm {
45 fn decode(input: &[u8]) -> Result<(&[u8], Self), DecodeError> {
46 let (input, publisher_id) = u8::decode(input)?;
47 let (input, publishing_ids) = Vec::decode(input)?;
48
49 Ok((
50 input,
51 PublishConfirm {
52 publisher_id,
53 publishing_ids,
54 },
55 ))
56 }
57}
58
59#[cfg(test)]
60mod tests {
61 use super::PublishConfirm;
62 use crate::commands::tests::command_encode_decode_test;
63
64 #[test]
65 fn publish_confirm_test() {
66 command_encode_decode_test::<PublishConfirm>()
67 }
68}