Skip to content

Commit b45646d

Browse files
authored
[ISSUE #1288]⚡️Add doc for MessageSysFlag and optimize code (#1289)
1 parent 86a9d6d commit b45646d

File tree

1 file changed

+34
-14
lines changed

1 file changed

+34
-14
lines changed

rocketmq-common/src/common/sys_flag/message_sys_flag.rs

+34-14
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,62 @@
11
use crate::common::compression::compression_type::CompressionType;
22

3+
// Meaning of each bit in the system flag
4+
///
5+
/// | bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
6+
/// |--------|---|---|-----------|----------|-------------|------------------|------------------|------------------|
7+
/// | byte 1 | | | STOREHOST | BORNHOST | TRANSACTION | TRANSACTION | MULTI_TAGS | COMPRESSED |
8+
/// | byte 2 | | | | | | COMPRESSION_TYPE | COMPRESSION_TYPE | COMPRESSION_TYPE |
9+
/// | byte 3 | | | | | | | | |
10+
/// | byte 4 | | | | | | | |
311
pub struct MessageSysFlag;
412

513
impl MessageSysFlag {
6-
pub const BORNHOST_V6_FLAG: i32 = 0x1 << 4;
714
pub const COMPRESSED_FLAG: i32 = 0x1;
8-
// COMPRESSION_TYPE
9-
pub const COMPRESSION_LZ4_TYPE: i32 = 0x1 << 8;
10-
pub const COMPRESSION_TYPE_COMPARATOR: i32 = 0x7 << 8;
11-
pub const COMPRESSION_ZLIB_TYPE: i32 = 0x3 << 8;
12-
pub const COMPRESSION_ZSTD_TYPE: i32 = 0x2 << 8;
13-
pub const INNER_BATCH_FLAG: i32 = 0x1 << 7;
1415
pub const MULTI_TAGS_FLAG: i32 = 0x1 << 1;
15-
pub const NEED_UNWRAP_FLAG: i32 = 0x1 << 6;
16-
pub const STOREHOSTADDRESS_V6_FLAG: i32 = 0x1 << 5;
17-
pub const TRANSACTION_COMMIT_TYPE: i32 = 0x2 << 2;
16+
17+
//Transaction related flag
1818
pub const TRANSACTION_NOT_TYPE: i32 = 0;
1919
pub const TRANSACTION_PREPARED_TYPE: i32 = 0x1 << 2;
20+
pub const TRANSACTION_COMMIT_TYPE: i32 = 0x2 << 2;
2021
pub const TRANSACTION_ROLLBACK_TYPE: i32 = 0x3 << 2;
2122

22-
pub fn get_transaction_value(flag: i32) -> i32 {
23+
//Flag of the message properties
24+
pub const BORNHOST_V6_FLAG: i32 = 0x1 << 4;
25+
pub const STOREHOSTADDRESS_V6_FLAG: i32 = 0x1 << 5;
26+
27+
//Mark the flag for batch to avoid conflict
28+
pub const NEED_UNWRAP_FLAG: i32 = 0x1 << 6;
29+
pub const INNER_BATCH_FLAG: i32 = 0x1 << 7;
30+
31+
// COMPRESSION_TYPE
32+
pub const COMPRESSION_LZ4_TYPE: i32 = 0x1 << 8;
33+
pub const COMPRESSION_ZSTD_TYPE: i32 = 0x2 << 8;
34+
pub const COMPRESSION_ZLIB_TYPE: i32 = 0x3 << 8;
35+
pub const COMPRESSION_TYPE_COMPARATOR: i32 = 0x7 << 8;
36+
37+
#[inline]
38+
pub const fn get_transaction_value(flag: i32) -> i32 {
2339
flag & Self::TRANSACTION_ROLLBACK_TYPE
2440
}
2541

26-
pub fn reset_transaction_value(flag: i32, transaction_type: i32) -> i32 {
42+
#[inline]
43+
pub const fn reset_transaction_value(flag: i32, transaction_type: i32) -> i32 {
2744
(flag & !Self::TRANSACTION_ROLLBACK_TYPE) | transaction_type
2845
}
2946

30-
pub fn clear_compressed_flag(flag: i32) -> i32 {
47+
#[inline]
48+
pub const fn clear_compressed_flag(flag: i32) -> i32 {
3149
flag & !Self::COMPRESSED_FLAG
3250
}
3351

52+
#[inline]
3453
pub fn get_compression_type(flag: i32) -> CompressionType {
3554
let compression_type_value = (flag & Self::COMPRESSION_TYPE_COMPARATOR) >> 8;
3655
CompressionType::find_by_value(compression_type_value)
3756
}
3857

39-
pub fn check(flag: i32, expected_flag: i32) -> bool {
58+
#[inline]
59+
pub const fn check(flag: i32, expected_flag: i32) -> bool {
4060
(flag & expected_flag) != 0
4161
}
4262
}

0 commit comments

Comments
 (0)