rocketmq_remoting/protocol/body/
connection.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 cheetah_string::CheetahString;
18use serde::Deserialize;
19use serde::Serialize;
20
21use crate::protocol::LanguageCode;
22
23#[derive(Deserialize, Serialize, Debug, Clone, Eq, PartialEq, Hash, Default)]
24#[serde(rename_all = "camelCase")]
25pub struct Connection {
26    client_id: CheetahString,
27    client_addr: CheetahString,
28    language: LanguageCode,
29    version: i32,
30}
31
32impl Connection {
33    pub fn new() -> Self {
34        Connection {
35            client_id: CheetahString::default(),
36            client_addr: CheetahString::default(),
37            language: LanguageCode::default(),
38            version: 0,
39        }
40    }
41}
42
43impl Connection {
44    pub fn get_client_id(&self) -> CheetahString {
45        self.client_id.clone()
46    }
47
48    pub fn set_client_id(&mut self, client_id: CheetahString) {
49        self.client_id = client_id;
50    }
51
52    pub fn get_client_addr(&self) -> CheetahString {
53        self.client_addr.clone()
54    }
55
56    pub fn set_client_addr(&mut self, client_addr: CheetahString) {
57        self.client_addr = client_addr;
58    }
59
60    pub fn get_language(&self) -> LanguageCode {
61        self.language
62    }
63
64    pub fn set_language(&mut self, language: LanguageCode) {
65        self.language = language;
66    }
67
68    pub fn get_version(&self) -> i32 {
69        self.version
70    }
71
72    pub fn set_version(&mut self, version: i32) {
73        self.version = version;
74    }
75}