diff options
| author | mat <github@matdoes.dev> | 2022-04-28 16:38:27 +0000 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-04-28 16:38:27 +0000 |
| commit | 1ca9caee36fb84e4a34be4d6b11399fcea8e8389 (patch) | |
| tree | 7f9cd6c31dffb46451a2bfd7fbf5ce95acb53e39 /azalea-protocol/src/mc_buf/mod.rs | |
| parent | 64823e661f24fbd8e7807d02b6097c1e5ae9c3be (diff) | |
| download | azalea-drasl-1ca9caee36fb84e4a34be4d6b11399fcea8e8389.tar.xz | |
add bitset and work on chunk packets
Diffstat (limited to 'azalea-protocol/src/mc_buf/mod.rs')
| -rwxr-xr-x | azalea-protocol/src/mc_buf/mod.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/azalea-protocol/src/mc_buf/mod.rs b/azalea-protocol/src/mc_buf/mod.rs index 3ab6e761..b69e94c4 100755 --- a/azalea-protocol/src/mc_buf/mod.rs +++ b/azalea-protocol/src/mc_buf/mod.rs @@ -4,13 +4,15 @@ mod read; mod write; pub use read::{McBufReadable, McBufVarintReadable, Readable}; -use std::ops::Deref; +use std::ops::{Deref, Index}; pub use write::{McBufVarintWritable, McBufWritable, Writable}; // const DEFAULT_NBT_QUOTA: u32 = 2097152; const MAX_STRING_LENGTH: u16 = 32767; // const MAX_COMPONENT_STRING_LENGTH: u32 = 262144; +// TODO: have a definitions.rs in mc_buf that contains UnsizedByteArray and BitSet + /// A Vec<u8> that isn't prefixed by a VarInt with the size. #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct UnsizedByteArray(Vec<u8>); @@ -29,6 +31,20 @@ impl From<Vec<u8>> for UnsizedByteArray { } } +/** Represents Java's BitSet, a list of bits. */ +pub struct BitSet { + data: Vec<u64>, +} + +impl Index<usize> for BitSet { + type Output = bool; + + fn index(&self, index: usize) -> &Self::Output { + let result = (self.data[index / 64] & (1u64 << (index % 64))) != 0; + &result + } +} + #[cfg(test)] mod tests { use super::*; |
