rocketmq_remoting/protocol/header/
get_max_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, RequestHeaderCodecV2)]
27#[serde(rename_all = "camelCase")]
28pub struct GetMaxOffsetRequestHeader {
29    pub topic: CheetahString,
30
31    pub queue_id: i32,
32
33    pub committed: bool,
34
35    #[serde(flatten)]
36    pub topic_request_header: Option<TopicRequestHeader>,
37}
38
39// impl Default for GetMaxOffsetRequestHeader {
40//     fn default() -> Self {
41//         GetMaxOffsetRequestHeader {
42//             topic: Default::default(),
43//             queue_id: Default::default(),
44//             committed: true,
45//             topic_request_header: Default::default(),
46//         }
47//     }
48// }
49
50// impl GetMaxOffsetRequestHeader {
51//     pub const TOPIC: &'static str = "topic";
52//     pub const QUEUE_ID: &'static str = "queueId";
53//     pub const COMMITTED: &'static str = "committed";
54// }
55
56// impl CommandCustomHeader for GetMaxOffsetRequestHeader {
57//     fn to_map(&self) -> Option<HashMap<CheetahString, CheetahString>> {
58//         let mut map = HashMap::new();
59//         map.insert(
60//             CheetahString::from_static_str(Self::TOPIC),
61//             self.topic.clone(),
62//         );
63//         map.insert(
64//             CheetahString::from_static_str(Self::QUEUE_ID),
65//             CheetahString::from_string(self.queue_id.to_string()),
66//         );
67//         map.insert(
68//             CheetahString::from_static_str(Self::COMMITTED),
69//             CheetahString::from_string(self.committed.to_string()),
70//         );
71//         if let Some(topic_request_header) = &self.topic_request_header {
72//             if let Some(topic_request_header_map) = topic_request_header.to_map() {
73//                 map.extend(topic_request_header_map);
74//             }
75//         }
76//         Some(map)
77//     }
78// }
79
80// impl FromMap for GetMaxOffsetRequestHeader {
81//     type Error = rocketmq_error::RocketmqError;
82
83//     type Target = Self;
84
85//     fn from(map: &HashMap<CheetahString, CheetahString>) -> Result<Self::Target, Self::Error> {
86//         Ok(GetMaxOffsetRequestHeader {
87//             topic: map
88//                 .get(&CheetahString::from_static_str(
89//                     GetMaxOffsetRequestHeader::TOPIC,
90//                 ))
91//                 .cloned()
92//                 .unwrap_or_default(),
93//             queue_id: map
94//                 .get(&CheetahString::from_static_str(
95//                     GetMaxOffsetRequestHeader::QUEUE_ID,
96//                 ))
97//                 .map(|s| s.parse().unwrap())
98//                 .unwrap_or_default(),
99//             committed: map
100//                 .get(&CheetahString::from_static_str(
101//                     GetMaxOffsetRequestHeader::COMMITTED,
102//                 ))
103//                 .map(|s| s.parse().unwrap())
104//                 .unwrap_or(true),
105//             topic_request_header: Some(<TopicRequestHeader as FromMap>::from(map)?),
106//         })
107//     }
108//}
109
110impl TopicRequestHeaderTrait for GetMaxOffsetRequestHeader {
111    fn set_lo(&mut self, lo: Option<bool>) {
112        self.topic_request_header.as_mut().unwrap().lo = lo;
113    }
114
115    fn lo(&self) -> Option<bool> {
116        self.topic_request_header.as_ref().unwrap().lo
117    }
118
119    fn set_topic(&mut self, topic: CheetahString) {
120        self.topic = topic;
121    }
122
123    fn topic(&self) -> &CheetahString {
124        &self.topic
125    }
126
127    fn broker_name(&self) -> Option<&CheetahString> {
128        self.topic_request_header
129            .as_ref()
130            .unwrap()
131            .rpc_request_header
132            .as_ref()
133            .unwrap()
134            .broker_name
135            .as_ref()
136    }
137
138    fn set_broker_name(&mut self, broker_name: CheetahString) {
139        self.topic_request_header
140            .as_mut()
141            .unwrap()
142            .rpc_request_header
143            .as_mut()
144            .unwrap()
145            .broker_name = Some(broker_name);
146    }
147
148    fn namespace(&self) -> Option<&str> {
149        self.topic_request_header
150            .as_ref()
151            .unwrap()
152            .rpc_request_header
153            .as_ref()
154            .unwrap()
155            .namespace
156            .as_deref()
157    }
158
159    fn set_namespace(&mut self, namespace: CheetahString) {
160        self.topic_request_header
161            .as_mut()
162            .unwrap()
163            .rpc_request_header
164            .as_mut()
165            .unwrap()
166            .namespace = Some(namespace);
167    }
168
169    fn namespaced(&self) -> Option<bool> {
170        self.topic_request_header
171            .as_ref()
172            .unwrap()
173            .rpc_request_header
174            .as_ref()
175            .unwrap()
176            .namespaced
177    }
178
179    fn set_namespaced(&mut self, namespaced: bool) {
180        self.topic_request_header
181            .as_mut()
182            .unwrap()
183            .rpc_request_header
184            .as_mut()
185            .unwrap()
186            .namespaced = Some(namespaced);
187    }
188
189    fn oneway(&self) -> Option<bool> {
190        self.topic_request_header
191            .as_ref()
192            .unwrap()
193            .rpc_request_header
194            .as_ref()
195            .unwrap()
196            .oneway
197    }
198
199    fn set_oneway(&mut self, oneway: bool) {
200        self.topic_request_header
201            .as_mut()
202            .unwrap()
203            .rpc_request_header
204            .as_mut()
205            .unwrap()
206            .oneway = Some(oneway);
207    }
208
209    fn queue_id(&self) -> i32 {
210        self.queue_id
211    }
212
213    fn set_queue_id(&mut self, queue_id: i32) {
214        self.queue_id = queue_id;
215    }
216}