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