rocketmq_common/common/message/
message_flag.rs1#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
17pub struct MessageFlag(i32);
18
19impl MessageFlag {
20 pub const NONE: Self = Self(0);
21 pub const COMPRESSED: Self = Self(1 << 0);
22 pub const MULTI_TAGS: Self = Self(1 << 1);
23 pub const TRANSACTION_PREPARED: Self = Self(1 << 2);
24 pub const TRANSACTION_COMMIT: Self = Self(1 << 3);
25 pub const TRANSACTION_ROLLBACK: Self = Self(1 << 4);
26
27 #[inline]
29 pub const fn empty() -> Self {
30 Self(0)
31 }
32
33 #[inline]
35 pub const fn from_bits(bits: i32) -> Self {
36 Self(bits)
37 }
38
39 #[inline]
41 pub const fn bits(&self) -> i32 {
42 self.0
43 }
44
45 #[inline]
47 pub const fn contains(&self, other: Self) -> bool {
48 (self.0 & other.0) == other.0
49 }
50
51 #[inline]
53 pub fn insert(&mut self, other: Self) {
54 self.0 |= other.0;
55 }
56
57 #[inline]
59 pub fn remove(&mut self, other: Self) {
60 self.0 &= !other.0;
61 }
62
63 #[inline]
65 pub fn is_compressed(&self) -> bool {
66 self.contains(Self::COMPRESSED)
67 }
68
69 #[inline]
71 pub fn is_multi_tags(&self) -> bool {
72 self.contains(Self::MULTI_TAGS)
73 }
74
75 #[inline]
77 pub fn is_transaction_prepared(&self) -> bool {
78 self.contains(Self::TRANSACTION_PREPARED)
79 }
80
81 #[inline]
83 pub fn is_transaction_commit(&self) -> bool {
84 self.contains(Self::TRANSACTION_COMMIT)
85 }
86
87 #[inline]
89 pub fn is_transaction_rollback(&self) -> bool {
90 self.contains(Self::TRANSACTION_ROLLBACK)
91 }
92}
93
94impl std::ops::BitOr for MessageFlag {
95 type Output = Self;
96
97 fn bitor(self, rhs: Self) -> Self::Output {
98 Self(self.0 | rhs.0)
99 }
100}
101
102impl std::ops::BitOrAssign for MessageFlag {
103 fn bitor_assign(&mut self, rhs: Self) {
104 self.0 |= rhs.0;
105 }
106}
107
108impl std::ops::BitAnd for MessageFlag {
109 type Output = Self;
110
111 fn bitand(self, rhs: Self) -> Self::Output {
112 Self(self.0 & rhs.0)
113 }
114}
115
116impl std::ops::BitAndAssign for MessageFlag {
117 fn bitand_assign(&mut self, rhs: Self) {
118 self.0 &= rhs.0;
119 }
120}
121
122impl From<i32> for MessageFlag {
123 fn from(value: i32) -> Self {
124 Self(value)
125 }
126}
127
128impl From<MessageFlag> for i32 {
129 fn from(flag: MessageFlag) -> Self {
130 flag.0
131 }
132}