rabbitmq_stream_protocol/commands/
delete_publisher.rs

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