rocketmq_common/common/message/
message_client_ext.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
use std::any::Any;
use std::collections::HashMap;
use std::fmt::Display;
use std::fmt::Formatter;

use bytes::Bytes;
use cheetah_string::CheetahString;

use crate::common::message::message_client_id_setter::MessageClientIDSetter;
use crate::common::message::message_ext::MessageExt;
use crate::common::message::MessageTrait;

#[derive(Clone, Debug, Default)]
pub struct MessageClientExt {
    pub message_ext_inner: MessageExt,
}

impl MessageClientExt {
    pub fn get_offset_msg_id(&self) -> &str {
        self.message_ext_inner.msg_id()
    }

    pub fn set_offset_msg_id(&mut self, offset_msg_id: impl Into<CheetahString>) {
        self.message_ext_inner.set_msg_id(offset_msg_id.into());
    }

    pub fn get_msg_id(&self) -> CheetahString {
        let uniq_id = MessageClientIDSetter::get_uniq_id(&self.message_ext_inner);
        if let Some(uniq_id) = uniq_id {
            uniq_id
        } else {
            self.message_ext_inner.msg_id().clone()
        }
    }
}

impl Display for MessageClientExt {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(
            f,
            "MessageClientExt {{ message_ext_inner: {:?} }}",
            self.message_ext_inner
        )
    }
}

impl MessageTrait for MessageClientExt {
    fn put_property(&mut self, key: CheetahString, value: CheetahString) {
        self.message_ext_inner.put_property(key, value);
    }

    fn clear_property(&mut self, name: &str) {
        self.message_ext_inner.clear_property(name);
    }

    fn get_property(&self, name: &CheetahString) -> Option<CheetahString> {
        self.message_ext_inner.get_property(name)
    }

    fn get_topic(&self) -> &CheetahString {
        self.message_ext_inner.get_topic()
    }

    fn set_topic(&mut self, topic: CheetahString) {
        self.message_ext_inner.set_topic(topic);
    }

    fn get_flag(&self) -> i32 {
        self.message_ext_inner.get_flag()
    }

    fn set_flag(&mut self, flag: i32) {
        self.message_ext_inner.set_flag(flag);
    }

    fn get_body(&self) -> Option<&Bytes> {
        self.message_ext_inner.get_body()
    }

    fn set_body(&mut self, body: Bytes) {
        self.message_ext_inner.set_body(body);
    }

    fn get_properties(&self) -> &HashMap<CheetahString, CheetahString> {
        self.message_ext_inner.get_properties()
    }

    fn set_properties(&mut self, properties: HashMap<CheetahString, CheetahString>) {
        self.message_ext_inner.set_properties(properties);
    }

    fn get_transaction_id(&self) -> &CheetahString {
        self.message_ext_inner.get_transaction_id()
    }

    fn set_transaction_id(&mut self, transaction_id: CheetahString) {
        self.message_ext_inner.set_transaction_id(transaction_id);
    }

    fn get_compressed_body_mut(&mut self) -> &mut Option<Bytes> {
        self.message_ext_inner.get_compressed_body_mut()
    }

    fn get_compressed_body(&self) -> Option<&Bytes> {
        self.message_ext_inner.get_compressed_body()
    }

    fn set_compressed_body_mut(&mut self, compressed_body: Bytes) {
        self.message_ext_inner
            .set_compressed_body_mut(compressed_body);
    }

    fn as_any(&self) -> &dyn Any {
        self
    }

    fn as_any_mut(&mut self) -> &mut dyn Any {
        self
    }
}