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_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).
Sourcepub fn finish_as_long(self) -> i64
pub fn finish_as_long(self) -> i64
Finishes hashing and returns the hash as a padded i64. Used for sorting map entries.