Skip to main content

ComponentHasher

Struct ComponentHasher 

Source
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

Source

pub const fn new() -> Self

Creates a new hasher.

Source

fn put_tag(&mut self, tag: HashTag)

Writes a raw tag byte.

Source

pub fn put_raw_bytes(&mut self, bytes: &[u8])

Writes raw bytes without any tag or length prefix.

Source

pub fn put_empty(&mut self)

Hashes an empty/null value.

Source

pub fn put_byte(&mut self, value: i8)

Hashes a byte (i8) value with tag.

Source

pub fn put_ubyte(&mut self, value: u8)

Hashes an unsigned byte (u8) value with tag.

Source

pub fn put_short(&mut self, value: i16)

Hashes a short (i16) value with tag. Guava uses little-endian byte order.

Source

pub fn put_int(&mut self, value: i32)

Hashes an int (i32) value with tag. Guava uses little-endian byte order.

Source

pub fn put_long(&mut self, value: i64)

Hashes a long (i64) value with tag. Guava uses little-endian byte order.

Source

pub fn put_float(&mut self, value: f32)

Hashes a float (f32) value with tag. Guava uses little-endian byte order.

Source

pub fn put_double(&mut self, value: f64)

Hashes a double (f64) value with tag. Guava uses little-endian byte order.

Source

pub fn put_bool(&mut self, value: bool)

Hashes a boolean value with tag.

Source

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-endian
  • putUnencodedChars writes each char as 2 bytes little-endian
Source

pub fn start_map(&mut self)

Starts a map/object. Call end_map() when done adding entries.

Source

pub fn end_map(&mut self)

Ends a map/object.

Source

pub fn start_list(&mut self)

Starts a list. Call end_list() when done adding elements.

Source

pub fn end_list(&mut self)

Ends a list.

Source

pub fn start_byte_array(&mut self)

Starts a byte array. Call end_byte_array() when done.

Source

pub fn end_byte_array(&mut self)

Ends a byte array.

Source

pub fn start_int_array(&mut self)

Starts an int array. Call end_int_array() when done.

Source

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.

Source

pub fn end_int_array(&mut self)

Ends an int array.

Source

pub fn start_long_array(&mut self)

Starts a long array. Call end_long_array() when done.

Source

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.

Source

pub fn end_long_array(&mut self)

Ends a long array.

Source

pub fn put_byte_array(&mut self, bytes: &[u8])

Hashes a byte array with start/end markers.

Source

pub fn put_int_array(&mut self, values: &[i32])

Hashes an int array with start/end markers.

Source

pub fn put_long_array(&mut self, values: &[i64])

Hashes a long array with start/end markers.

Source

pub fn current_data(&self) -> &[u8]

Returns the current hash data (for nested hashing).

Source

pub fn finish(self) -> i32

Finishes hashing and returns the CRC32C checksum as i32.

Source

pub fn finish_as_long(self) -> i64

Finishes hashing and returns the hash as a padded i64. Used for sorting map entries.

Trait Implementations§

Source§

impl Default for ComponentHasher

Source§

fn default() -> ComponentHasher

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more