rocketmq_protocol/protocol/
request_type.rs1use std::fmt::Display;
16
17#[derive(Debug, PartialEq, Eq, Clone, Copy)]
18pub enum RequestType {
19 Stream,
20}
21
22impl Display for RequestType {
23 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24 match self {
25 RequestType::Stream => write!(f, "STREAM"),
26 }
27 }
28}
29
30impl RequestType {
31 pub fn value_of(code: u8) -> Option<Self> {
32 match code {
33 0 => Some(RequestType::Stream),
34 _ => None,
35 }
36 }
37
38 pub fn get_code(&self) -> u8 {
39 match self {
40 RequestType::Stream => 0,
41 }
42 }
43}
44
45#[cfg(test)]
46mod tests {
47 use super::*;
48
49 #[test]
50 fn value_of_maps_zero_to_stream() {
51 assert_eq!(RequestType::value_of(0), Some(RequestType::Stream));
52 }
53
54 #[test]
55 fn value_of_rejects_unknown_codes() {
56 assert_eq!(RequestType::value_of(1), None);
57 assert_eq!(RequestType::value_of(255), None);
58 }
59
60 #[test]
61 fn get_code_returns_zero_for_stream() {
62 assert_eq!(RequestType::Stream.get_code(), 0);
63 }
64
65 #[test]
66 fn display_prints_stream_for_stream_variant() {
67 assert_eq!(RequestType::Stream.to_string(), "STREAM");
68 }
69}