-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename
InitMessageArrays
into InitMessageFlags
I planning to encode other things inside it. Also this name fits better in general.
- Loading branch information
Showing
6 changed files
with
95 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use bitflags::bitflags; | ||
|
||
bitflags! { | ||
/// Types of data included in the change message if the bit is set. | ||
/// | ||
/// Serialized at the beginning of the message. | ||
#[derive(Default, Clone, Copy, PartialEq, Eq, Debug)] | ||
pub(crate) struct ChangeMessageFlags: u8 { | ||
const MAPPINGS = 0b00000001; | ||
const DESPAWNS = 0b00000010; | ||
const REMOVALS = 0b00000100; | ||
const CHANGES = 0b00001000; | ||
} | ||
} | ||
|
||
impl ChangeMessageFlags { | ||
/// Returns the last set flag in the message. | ||
pub(crate) fn last(self) -> ChangeMessageFlags { | ||
debug_assert!(!self.is_empty()); | ||
let zeroes = u8::BITS - 1 - self.bits().leading_zeros(); | ||
ChangeMessageFlags::from_bits_retain(1 << zeroes) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn last() { | ||
assert_eq!( | ||
ChangeMessageFlags::CHANGES.last(), | ||
ChangeMessageFlags::CHANGES | ||
); | ||
assert_eq!( | ||
ChangeMessageFlags::MAPPINGS.last(), | ||
ChangeMessageFlags::MAPPINGS | ||
); | ||
assert_eq!( | ||
ChangeMessageFlags::all().last(), | ||
ChangeMessageFlags::CHANGES | ||
); | ||
assert_eq!( | ||
(ChangeMessageFlags::DESPAWNS | ChangeMessageFlags::REMOVALS).last(), | ||
ChangeMessageFlags::REMOVALS | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters