Skip to content

[ISSUE #1288]⚡️Add doc for MessageSysFlag and optimize code #1289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 34 additions & 14 deletions rocketmq-common/src/common/sys_flag/message_sys_flag.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,62 @@
use crate::common::compression::compression_type::CompressionType;

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

impl MessageSysFlag {
pub const BORNHOST_V6_FLAG: i32 = 0x1 << 4;
pub const COMPRESSED_FLAG: i32 = 0x1;
// COMPRESSION_TYPE
pub const COMPRESSION_LZ4_TYPE: i32 = 0x1 << 8;
pub const COMPRESSION_TYPE_COMPARATOR: i32 = 0x7 << 8;
pub const COMPRESSION_ZLIB_TYPE: i32 = 0x3 << 8;
pub const COMPRESSION_ZSTD_TYPE: i32 = 0x2 << 8;
pub const INNER_BATCH_FLAG: i32 = 0x1 << 7;
pub const MULTI_TAGS_FLAG: i32 = 0x1 << 1;
pub const NEED_UNWRAP_FLAG: i32 = 0x1 << 6;
pub const STOREHOSTADDRESS_V6_FLAG: i32 = 0x1 << 5;
pub const TRANSACTION_COMMIT_TYPE: i32 = 0x2 << 2;

//Transaction related flag
pub const TRANSACTION_NOT_TYPE: i32 = 0;
pub const TRANSACTION_PREPARED_TYPE: i32 = 0x1 << 2;
pub const TRANSACTION_COMMIT_TYPE: i32 = 0x2 << 2;
pub const TRANSACTION_ROLLBACK_TYPE: i32 = 0x3 << 2;

pub fn get_transaction_value(flag: i32) -> i32 {
//Flag of the message properties
pub const BORNHOST_V6_FLAG: i32 = 0x1 << 4;
pub const STOREHOSTADDRESS_V6_FLAG: i32 = 0x1 << 5;

//Mark the flag for batch to avoid conflict
pub const NEED_UNWRAP_FLAG: i32 = 0x1 << 6;
pub const INNER_BATCH_FLAG: i32 = 0x1 << 7;

// COMPRESSION_TYPE
pub const COMPRESSION_LZ4_TYPE: i32 = 0x1 << 8;
pub const COMPRESSION_ZSTD_TYPE: i32 = 0x2 << 8;
pub const COMPRESSION_ZLIB_TYPE: i32 = 0x3 << 8;
pub const COMPRESSION_TYPE_COMPARATOR: i32 = 0x7 << 8;

#[inline]
pub const fn get_transaction_value(flag: i32) -> i32 {
flag & Self::TRANSACTION_ROLLBACK_TYPE
}

pub fn reset_transaction_value(flag: i32, transaction_type: i32) -> i32 {
#[inline]
pub const fn reset_transaction_value(flag: i32, transaction_type: i32) -> i32 {
(flag & !Self::TRANSACTION_ROLLBACK_TYPE) | transaction_type
}

pub fn clear_compressed_flag(flag: i32) -> i32 {
#[inline]
pub const fn clear_compressed_flag(flag: i32) -> i32 {
flag & !Self::COMPRESSED_FLAG
}

#[inline]
pub fn get_compression_type(flag: i32) -> CompressionType {
let compression_type_value = (flag & Self::COMPRESSION_TYPE_COMPARATOR) >> 8;
CompressionType::find_by_value(compression_type_value)
}

pub fn check(flag: i32, expected_flag: i32) -> bool {
#[inline]
pub const fn check(flag: i32, expected_flag: i32) -> bool {
(flag & expected_flag) != 0
}
}
Expand Down
Loading