rocketmq_remoting/protocol/header/
get_min_offset_request_header.rs

1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements.  See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License.  You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18use cheetah_string::CheetahString;
19use rocketmq_macros::RequestHeaderCodecV2;
20use serde::Deserialize;
21use serde::Serialize;
22
23use crate::protocol::header::message_operation_header::TopicRequestHeaderTrait;
24use crate::rpc::topic_request_header::TopicRequestHeader;
25
26#[derive(Debug, Clone, Serialize, Deserialize, Default, RequestHeaderCodecV2)]
27#[serde(rename_all = "camelCase")]
28pub struct GetMinOffsetRequestHeader {
29    pub topic: CheetahString,
30
31    pub queue_id: i32,
32
33    #[serde(flatten)]
34    pub topic_request_header: Option<TopicRequestHeader>,
35}
36
37// impl GetMinOffsetRequestHeader {
38//     pub const TOPIC: &'static str = "topic";
39//     pub const QUEUE_ID: &'static str = "queueId";
40// }
41
42// impl CommandCustomHeader for GetMinOffsetRequestHeader {
43//     fn to_map(&self) -> Option<HashMap<CheetahString, CheetahString>> {
44//         let mut map = HashMap::new();
45//         map.insert(
46//             CheetahString::from_static_str(Self::TOPIC),
47//             self.topic.clone(),
48//         );
49//         map.insert(
50//             CheetahString::from_static_str(Self::QUEUE_ID),
51//             CheetahString::from_string(self.queue_id.to_string()),
52//         );
53//         if let Some(topic_request_header) = &self.topic_request_header {
54//             if let Some(topic_request_header_map) = topic_request_header.to_map() {
55//                 map.extend(topic_request_header_map);
56//             }
57//         }
58//         Some(map)
59//     }
60// }
61
62// impl FromMap for GetMinOffsetRequestHeader {
63//     type Error = rocketmq_error::RocketmqError;
64
65//     type Target = Self;
66
67//     fn from(map: &HashMap<CheetahString, CheetahString>) -> Result<Self::Target, Self::Error> {
68//         Ok(GetMinOffsetRequestHeader {
69//             topic: map
70//                 .get(&CheetahString::from_static_str(
71//                     GetMinOffsetRequestHeader::TOPIC,
72//                 ))
73//                 .cloned()
74//                 .unwrap_or_default(),
75//             queue_id: map
76//                 .get(&CheetahString::from_static_str(
77//                     GetMinOffsetRequestHeader::QUEUE_ID,
78//                 ))
79//                 .map(|s| s.parse().unwrap())
80//                 .unwrap_or_default(),
81//             topic_request_header: Some(<TopicRequestHeader as FromMap>::from(map)?),
82//         })
83//     }
84// }
85
86impl TopicRequestHeaderTrait for GetMinOffsetRequestHeader {
87    fn set_lo(&mut self, lo: Option<bool>) {
88        self.topic_request_header.as_mut().unwrap().lo = lo;
89    }
90
91    fn lo(&self) -> Option<bool> {
92        self.topic_request_header.as_ref().unwrap().lo
93    }
94
95    fn set_topic(&mut self, topic: CheetahString) {
96        self.topic = topic;
97    }
98
99    fn topic(&self) -> &CheetahString {
100        &self.topic
101    }
102
103    fn broker_name(&self) -> Option<&CheetahString> {
104        self.topic_request_header
105            .as_ref()
106            .and_then(|h| h.rpc_request_header.as_ref())
107            .and_then(|h| h.broker_name.as_ref())
108    }
109
110    fn set_broker_name(&mut self, broker_name: CheetahString) {
111        self.topic_request_header
112            .as_mut()
113            .unwrap()
114            .rpc_request_header
115            .as_mut()
116            .unwrap()
117            .broker_name = Some(broker_name);
118    }
119
120    fn namespace(&self) -> Option<&str> {
121        self.topic_request_header
122            .as_ref()
123            .unwrap()
124            .rpc_request_header
125            .as_ref()
126            .unwrap()
127            .namespace
128            .as_deref()
129    }
130
131    fn set_namespace(&mut self, namespace: CheetahString) {
132        self.topic_request_header
133            .as_mut()
134            .unwrap()
135            .rpc_request_header
136            .as_mut()
137            .unwrap()
138            .namespace = Some(namespace);
139    }
140
141    fn namespaced(&self) -> Option<bool> {
142        self.topic_request_header
143            .as_ref()
144            .unwrap()
145            .rpc_request_header
146            .as_ref()
147            .unwrap()
148            .namespaced
149    }
150
151    fn set_namespaced(&mut self, namespaced: bool) {
152        self.topic_request_header
153            .as_mut()
154            .unwrap()
155            .rpc_request_header
156            .as_mut()
157            .unwrap()
158            .namespaced = Some(namespaced);
159    }
160
161    fn oneway(&self) -> Option<bool> {
162        self.topic_request_header
163            .as_ref()
164            .unwrap()
165            .rpc_request_header
166            .as_ref()
167            .unwrap()
168            .oneway
169    }
170
171    fn set_oneway(&mut self, oneway: bool) {
172        self.topic_request_header
173            .as_mut()
174            .unwrap()
175            .rpc_request_header
176            .as_mut()
177            .unwrap()
178            .oneway = Some(oneway);
179    }
180
181    fn queue_id(&self) -> i32 {
182        self.queue_id
183    }
184
185    fn set_queue_id(&mut self, queue_id: i32) {
186        self.queue_id = queue_id;
187    }
188}