pub struct ComponentHasher {
data: Vec<u8>,
}Expand description
A CRC32C hasher for component values.
This hasher is designed to produce the same hashes as Minecraft’s
HashOps implementation using Guava’s Hashing.crc32c().
§Example
use steel_utils::hash::ComponentHasher;
let mut hasher = ComponentHasher::new();
hasher.put_int(42);
let hash = hasher.finish();Fields§
§data: Vec<u8>Implementations§
Source§impl ComponentHasher
impl ComponentHasher
Sourcepub fn put_raw_bytes(&mut self, bytes: &[u8])
pub fn put_raw_bytes(&mut self, bytes: &[u8])
Writes raw bytes without any tag or length prefix.
Sourcepub fn put_component_hash<T: HashComponent + ?Sized>(&mut self, value: &T)
pub fn put_component_hash<T: HashComponent + ?Sized>(&mut self, value: &T)
Writes the four-byte hash of a nested codec value.
Vanilla lists contain child hashes rather than each child’s unhashed payload.
Sourcepub fn put_short(&mut self, value: i16)
pub fn put_short(&mut self, value: i16)
Hashes a short (i16) value with tag. Guava uses little-endian byte order.
Sourcepub fn put_int(&mut self, value: i32)
pub fn put_int(&mut self, value: i32)
Hashes an int (i32) value with tag. Guava uses little-endian byte order.
Sourcepub fn put_long(&mut self, value: i64)
pub fn put_long(&mut self, value: i64)
Hashes a long (i64) value with tag. Guava uses little-endian byte order.
Sourcepub fn put_float(&mut self, value: f32)
pub fn put_float(&mut self, value: f32)
Hashes a float (f32) value with tag. Guava uses little-endian byte order.
Sourcepub fn put_double(&mut self, value: f64)
pub fn put_double(&mut self, value: f64)
Hashes a double (f64) value with tag. Guava uses little-endian byte order.
Sourcepub fn put_string(&mut self, value: &str)
pub fn put_string(&mut self, value: &str)
Hashes a string value with tag, length prefix, and UTF-16 LE characters.
This matches Guava’s Hasher which uses little-endian for all primitives:
putInt(length)writes length as 4 bytes little-endianputUnencodedCharswrites each char as 2 bytes little-endian
Sourcepub fn start_list(&mut self)
pub fn start_list(&mut self)
Starts a list. Call end_list() when done adding elements.
Sourcepub fn start_byte_array(&mut self)
pub fn start_byte_array(&mut self)
Starts a byte array. Call end_byte_array() when done.
Sourcepub fn end_byte_array(&mut self)
pub fn end_byte_array(&mut self)
Ends a byte array.
Sourcepub fn start_int_array(&mut self)
pub fn start_int_array(&mut self)
Starts an int array. Call end_int_array() when done.
Sourcepub fn put_int_raw(&mut self, value: i32)
pub fn put_int_raw(&mut self, value: i32)
Writes an int value without tag (for use inside int arrays). Guava uses little-endian byte order.
Sourcepub fn end_int_array(&mut self)
pub fn end_int_array(&mut self)
Ends an int array.
Sourcepub fn start_long_array(&mut self)
pub fn start_long_array(&mut self)
Starts a long array. Call end_long_array() when done.
Sourcepub fn put_long_raw(&mut self, value: i64)
pub fn put_long_raw(&mut self, value: i64)
Writes a long value without tag (for use inside long arrays). Guava uses little-endian byte order.
Sourcepub fn end_long_array(&mut self)
pub fn end_long_array(&mut self)
Ends a long array.
Sourcepub fn put_byte_array(&mut self, bytes: &[u8])
pub fn put_byte_array(&mut self, bytes: &[u8])
Hashes a byte array with start/end markers.
Sourcepub fn put_int_array(&mut self, values: &[i32])
pub fn put_int_array(&mut self, values: &[i32])
Hashes an int array with start/end markers.
Sourcepub fn put_long_array(&mut self, values: &[i64])
pub fn put_long_array(&mut self, values: &[i64])
Hashes a long array with start/end markers.
Sourcepub fn current_data(&self) -> &[u8] ⓘ
pub fn current_data(&self) -> &[u8] ⓘ
Returns the current hash data (for nested hashing).
Trait Implementations§
Source§impl Default for ComponentHasher
impl Default for ComponentHasher
Source§fn default() -> ComponentHasher
fn default() -> ComponentHasher
Auto Trait Implementations§
impl Freeze for ComponentHasher
impl RefUnwindSafe for ComponentHasher
impl Send for ComponentHasher
impl Sync for ComponentHasher
impl Unpin for ComponentHasher
impl UnsafeUnpin for ComponentHasher
impl UnwindSafe for ComponentHasher
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreArc<SyncMutex<>>