22def nyx_hash(string: str | bytes |
None, seed: int) -> int:
25 @brief Hashes a string using the MurmurHash2 algorithm.
27 @param string String to hash.
28 @param seed Initial seed value.
29 @return The computed 32-bit hash.
34 return int(seed) & 0xFFFFFFFF
38 data = bind.as_bytes(string, allow_none =
False)
40 return int(bind.lib.nyx_hash(len(data), data, int(seed) & 0xFFFFFFFF))
47 @brief Generates a MAC address based on a node identifier.
49 @param mac0 First fixed byte of the MAC address.
50 @param mac1 Second fixed byte of the MAC address.
51 @param node_id Unique node identifier used to hash the remaining bytes.
52 @return The generated MAC address.
57 node_id = bind.as_bytes(node_id, allow_none =
False)
61 result_mac = (bind.c_uint8 * 6)()
63 bind.lib.nyx_generate_mac_addr(
70 return bytes(result_mac)
77 @brief Encodes a buffer using the Base64 algorithm.
79 @param data Data to encode.
80 @return The encoded string, or None when no data is provided.
89 data = bind.as_bytes(data, allow_none =
False)
93 result_size = bind.c_size_t()
95 result_buff = bind.lib.nyx_base64_encode(ctypes.byref(result_size), len(data), data)
97 return bind.take_string(result_buff, result_size.value)
104 @brief Decodes a string using the Base64 algorithm.
106 @param data Base64 data to decode.
107 @return The decoded buffer, or None when no data is provided.
116 data = bind.as_bytes(data, allow_none =
False)
120 result_size = bind.c_size_t()
122 result_buff = bind.lib.nyx_base64_decode(ctypes.byref(result_size), len(data), data)
124 return bind.take_bytes(result_buff, result_size.value)
128__all__ = [name
for name
in globals()
if name.lower().startswith(
'nyx')]
uint32_t nyx_hash(__NYX_ZEROABLE__ size_t size, __NYX_NULLABLE__ BUFF_t buff, uint32_t seed)
Hashes a buffer using the MurmurHash2 algorithm.
__NYX_NULLABLE__ str_t nyx_base64_encode(__NYX_NULLABLE__ size_t *result_len, __NYX_ZEROABLE__ size_t size, __NYX_NULLABLE__ BUFF_t buff)
Encodes a buffer using the Base64 algorithm.
__NYX_NULLABLE__ buff_t nyx_base64_decode(__NYX_NULLABLE__ size_t *result_size, __NYX_ZEROABLE__ size_t len, __NYX_NULLABLE__ STR_t str)
Decodes a string using the Base64 algorithm.
void nyx_generate_mac_addr(uint8_t result_mac[6], uint8_t mac0, uint8_t mac1, STR_t node_id)
Generates a MAC address based on a node identifier.