rocketmq_remoting/protocol/heartbeat/
subscription_data.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 std::collections::HashSet;
19use std::hash::Hash;
20use std::hash::Hasher;
21
22use cheetah_string::CheetahString;
23use rocketmq_common::common::filter::expression_type::ExpressionType;
24use rocketmq_common::TimeUtils::get_current_millis;
25use serde::Deserialize;
26use serde::Serialize;
27
28#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
29#[serde(rename_all = "camelCase")]
30pub struct SubscriptionData {
31    pub class_filter_mode: bool,
32    pub topic: CheetahString,
33    pub sub_string: CheetahString,
34    pub tags_set: HashSet<CheetahString>,
35    pub code_set: HashSet<i32>,
36    pub sub_version: i64,
37    pub expression_type: CheetahString,
38    // In Rust, attributes like `@JSONField(serialize = false)` are typically handled through
39    // documentation or external crates.
40    #[serde(skip)]
41    pub filter_class_source: CheetahString, // This field is not used in this example.
42}
43
44impl Default for SubscriptionData {
45    fn default() -> Self {
46        SubscriptionData {
47            class_filter_mode: false,
48            topic: CheetahString::new(),
49            sub_string: CheetahString::new(),
50            tags_set: HashSet::new(),
51            code_set: HashSet::new(),
52            sub_version: get_current_millis() as i64,
53            expression_type: CheetahString::from_static_str(ExpressionType::TAG),
54            filter_class_source: CheetahString::new(),
55        }
56    }
57}
58
59impl SubscriptionData {
60    pub const SUB_ALL: &'static str = "*";
61}
62
63impl Hash for SubscriptionData {
64    fn hash<H: Hasher>(&self, state: &mut H) {
65        self.class_filter_mode.hash(state);
66        self.topic.hash(state);
67        self.sub_string.hash(state);
68        self.tags_set.iter().for_each(|tag| tag.hash(state));
69        self.code_set.iter().for_each(|code| code.hash(state));
70        self.sub_version.hash(state);
71        self.expression_type.hash(state);
72        self.filter_class_source.hash(state);
73    }
74}