rabbitmq_stream_protocol/commands/
mod.rs

1use crate::protocol::version::PROTOCOL_VERSION;
2
3pub mod close;
4pub mod consumer_update;
5pub mod consumer_update_request;
6pub mod create_stream;
7pub mod create_super_stream;
8pub mod credit;
9pub mod declare_publisher;
10pub mod delete;
11pub mod delete_publisher;
12pub mod delete_super_stream;
13pub mod deliver;
14pub mod exchange_command_versions;
15pub mod generic;
16pub mod heart_beat;
17pub mod metadata;
18pub mod metadata_update;
19pub mod open;
20pub mod peer_properties;
21pub mod publish;
22pub mod publish_confirm;
23pub mod publish_error;
24pub mod query_offset;
25pub mod query_publisher_sequence;
26pub mod sasl_authenticate;
27pub mod sasl_handshake;
28pub mod store_offset;
29pub mod subscribe;
30pub mod superstream_partitions;
31pub mod superstream_route;
32pub mod tune;
33pub mod unsubscribe;
34
35pub trait Command {
36    fn key(&self) -> u16;
37    fn version(&self) -> u16 {
38        PROTOCOL_VERSION
39    }
40}
41
42#[cfg(test)]
43mod tests {
44
45    use std::fmt::Debug;
46
47    use crate::codec::{Decoder, Encoder};
48    use fake::{Dummy, Fake, Faker};
49    pub(crate) fn command_encode_decode_test<T>()
50    where
51        T: Dummy<Faker> + Encoder + Decoder + Debug + PartialEq,
52    {
53        let mut buffer = vec![];
54
55        let open: T = Faker.fake();
56
57        let _ = open.encode(&mut buffer);
58
59        let (remaining, decoded) = T::decode(&buffer).unwrap();
60
61        assert_eq!(open, decoded);
62
63        assert!(remaining.is_empty());
64    }
65
66    pub(crate) fn specific_command_encode_decode_test<T>(command: T)
67    where
68        T: Encoder + Decoder + Debug + PartialEq,
69    {
70        let mut buffer = vec![];
71
72        let _ = command.encode(&mut buffer);
73
74        let (remaining, decoded) = T::decode(&buffer).unwrap();
75
76        assert_eq!(command, decoded);
77
78        assert!(remaining.is_empty());
79    }
80}