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