rocketmq_common/common/message/
message_client_ext.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 */
17use std::any::Any;
18use std::collections::HashMap;
19use std::fmt::Display;
20use std::fmt::Formatter;
21
22use bytes::Bytes;
23use cheetah_string::CheetahString;
24
25use crate::common::message::message_client_id_setter::MessageClientIDSetter;
26use crate::common::message::message_ext::MessageExt;
27use crate::common::message::MessageTrait;
28
29#[derive(Clone, Debug, Default)]
30pub struct MessageClientExt {
31    pub message_ext_inner: MessageExt,
32}
33
34impl MessageClientExt {
35    pub fn new(message: MessageExt) -> Self {
36        Self {
37            message_ext_inner: message,
38        }
39    }
40
41    pub fn get_offset_msg_id(&self) -> &str {
42        self.message_ext_inner.msg_id()
43    }
44
45    pub fn set_offset_msg_id(&mut self, offset_msg_id: impl Into<CheetahString>) {
46        self.message_ext_inner.set_msg_id(offset_msg_id.into());
47    }
48
49    pub fn get_msg_id(&self) -> CheetahString {
50        let uniq_id = MessageClientIDSetter::get_uniq_id(&self.message_ext_inner);
51        if let Some(uniq_id) = uniq_id {
52            uniq_id
53        } else {
54            self.message_ext_inner.msg_id().clone()
55        }
56    }
57}
58
59impl Display for MessageClientExt {
60    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
61        write!(
62            f,
63            "MessageClientExt {{ message_ext_inner: {:?} }}",
64            self.message_ext_inner
65        )
66    }
67}
68
69impl MessageTrait for MessageClientExt {
70    #[inline]
71    fn put_property(&mut self, key: CheetahString, value: CheetahString) {
72        self.message_ext_inner.put_property(key, value);
73    }
74
75    #[inline]
76    fn clear_property(&mut self, name: &str) {
77        self.message_ext_inner.clear_property(name);
78    }
79
80    #[inline]
81    fn get_property(&self, name: &CheetahString) -> Option<CheetahString> {
82        self.message_ext_inner.get_property(name)
83    }
84
85    #[inline]
86    fn get_topic(&self) -> &CheetahString {
87        self.message_ext_inner.get_topic()
88    }
89
90    #[inline]
91    fn set_topic(&mut self, topic: CheetahString) {
92        self.message_ext_inner.set_topic(topic);
93    }
94
95    #[inline]
96    fn get_flag(&self) -> i32 {
97        self.message_ext_inner.get_flag()
98    }
99
100    #[inline]
101    fn set_flag(&mut self, flag: i32) {
102        self.message_ext_inner.set_flag(flag);
103    }
104
105    #[inline]
106    fn get_body(&self) -> Option<&Bytes> {
107        self.message_ext_inner.get_body()
108    }
109
110    #[inline]
111    fn set_body(&mut self, body: Bytes) {
112        self.message_ext_inner.set_body(body);
113    }
114
115    #[inline]
116    fn get_properties(&self) -> &HashMap<CheetahString, CheetahString> {
117        self.message_ext_inner.get_properties()
118    }
119
120    #[inline]
121    fn set_properties(&mut self, properties: HashMap<CheetahString, CheetahString>) {
122        self.message_ext_inner.set_properties(properties);
123    }
124
125    #[inline]
126    fn get_transaction_id(&self) -> Option<&CheetahString> {
127        self.message_ext_inner.get_transaction_id()
128    }
129
130    #[inline]
131    fn set_transaction_id(&mut self, transaction_id: CheetahString) {
132        self.message_ext_inner.set_transaction_id(transaction_id);
133    }
134
135    #[inline]
136    fn get_compressed_body_mut(&mut self) -> &mut Option<Bytes> {
137        self.message_ext_inner.get_compressed_body_mut()
138    }
139
140    #[inline]
141    fn get_compressed_body(&self) -> Option<&Bytes> {
142        self.message_ext_inner.get_compressed_body()
143    }
144
145    #[inline]
146    fn set_compressed_body_mut(&mut self, compressed_body: Bytes) {
147        self.message_ext_inner
148            .set_compressed_body_mut(compressed_body);
149    }
150
151    #[inline]
152    fn take_body(&mut self) -> Option<Bytes> {
153        self.message_ext_inner.take_body()
154    }
155
156    #[inline]
157    fn as_any(&self) -> &dyn Any {
158        self
159    }
160
161    #[inline]
162    fn as_any_mut(&mut self) -> &mut dyn Any {
163        self
164    }
165}