Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

alexandria_bytes

Fully qualified path: alexandria_bytes

Modules


Re-exports:

BytesNote that: In Bytes, there are many variables about size and length. We use size to represent the number of bytes in Bytes. We use length to represent the number of elements in Bytes….


BytesIndexImplementation of IndexView trait for Bytes. Allows indexing into the Bytes structure to access individual u128 elements.
BytesStoreStore for a Bytes object. The layout of a Bytes object in storage is as follows:…

Modules

Modules

bit_array

Fully qualified path: alexandria_bytes::bit_array

Free functions

shift_bitComputes 2^number for bit positions 0-7 within a byte This helper function returns the value of 2 raised to the given power,…
one_shift_left_bytes_felt252Computes 256^n_bytes for felt252 byte shifting operations This function calculates the value needed to shift bytes within a felt252 value….
one_shift_left_bytes_u128Computes 256^n_bytes for u128 byte shifting operations This function provides a lookup table for powers of 256 up to 256^15, which covers the full range of byte positions within a u128 value….

Structs

Traits

Free functions

Free functions

shift_bitComputes 2^number for bit positions 0-7 within a byte This helper function returns the value of 2 raised to the given power,…
one_shift_left_bytes_felt252Computes 256^n_bytes for felt252 byte shifting operations This function calculates the value needed to shift bytes within a felt252 value….
one_shift_left_bytes_u128Computes 256^n_bytes for u128 byte shifting operations This function provides a lookup table for powers of 256 up to 256^15, which covers the full range of byte positions within a u128 value….

shift_bit

Computes 2^number for bit positions 0-7 within a byte

This helper function returns the value of 2 raised to the given power, specifically designed for bit manipulation within a single byte (0-7 bit positions). It provides fast lookup for common bit shift operations.

Arguments

  • number - The bit position (0-7) to compute 2^number for

Returns

  • u8 - The value 2^number as a u8, panics if number > 7

Fully qualified path: alexandria_bytes::bit_array::shift_bit

pub fn shift_bit(number: u32) -> u8

one_shift_left_bytes_felt252

Computes 256^n_bytes for felt252 byte shifting operations

This function calculates the value needed to shift bytes within a felt252 value. Since felt252 can hold up to 31 bytes, this function handles the full range by splitting calculations between the low and high 128-bit parts when necessary.

Arguments

  • n_bytes - The number of byte positions to shift (0-30)

Returns

  • felt252 - The value 256^n_bytes for byte shifting operations

Fully qualified path: alexandria_bytes::bit_array::one_shift_left_bytes_felt252

pub fn one_shift_left_bytes_felt252(n_bytes: u32) -> felt252

one_shift_left_bytes_u128

Computes 256^n_bytes for u128 byte shifting operations

This function provides a lookup table for powers of 256 up to 256^15, which covers the full range of byte positions within a u128 value. Each position represents shifting by one byte (8 bits) to the left.

Arguments

  • n_bytes - The number of byte positions to shift (0-15)

Returns

  • u128 - The value 256^n_bytes, panics if n_bytes > 15

Fully qualified path: alexandria_bytes::bit_array::one_shift_left_bytes_u128

pub fn one_shift_left_bytes_u128(n_bytes: u32) -> u128

Structs

Structs

BitArray

Fully qualified path: alexandria_bytes::bit_array::BitArray

[derive(Clone, Drop)]
pub struct BitArray { /* private fields */ }

Traits

Traits

BitArrayTrait

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait

pub trait BitArrayTrait

Trait functions

new

Creates a new BitArray instance.

Arguments

  • data - Array of bytes31 data
  • current - Current working felt252 value
  • read_pos - Current read position
  • write_pos - Current write position

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::new

fn new(data: Array<bytes31>, current: felt252, read_pos: u32, write_pos: u32) -> BitArray

current

Gets the current working felt252 value.

Arguments

  • self - The BitArray to get the current value from

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::current

fn current(self: @BitArray) -> felt252

data

Gets the underlying data array.

Arguments

  • self - The BitArray to get the data from

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::data

fn data(self: BitArray) -> Array<bytes31>

append_bit

Appends a single bit to the BitArray

Arguments

  • self - The BitArray to append to
  • bit - either true or false, representing a single bit to be appended

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::append_bit

fn append_bit(ref self: BitArray, bit: bool)

at

Reads a single bit from the array

Arguments

  • self - The BitArray to read from
  • index - the index into the array to read

Returns

Option<bool> - if the index is found, the stored bool is returned

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::at

fn at(self: @BitArray, index: u32) -> Option<bool>

len

The current length of the BitArray

Arguments

  • self - The BitArray to get the length of

Returns

usize - length in bits of the BitArray

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::len

fn len(self: @BitArray) -> u32

pop_front

Returns and removes the first element of the BitArray

Arguments

  • self - The BitArray to pop from

Returns

Option<bool> - If the array is non-empty, a bool is removed from the front and returned

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::pop_front

fn pop_front(ref self: BitArray) -> Option<bool>

read_word_be

Reads a single word of the specified length up to 248 bits in big endian bit representation

Arguments

  • self - The BitArray to read from
  • length - The bit length of the word to read, max 248

Returns

Option<felt252> - If there are length bits remaining, the word is returned as felt252

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::read_word_be

fn read_word_be(ref self: BitArray, length: u32) -> Option<felt252>

read_word_be_u256

Reads a single word of the specified length up to 256 bits in big endian representation. For words shorter than (or equal to) 248 bits use read_word_be(...) instead.

Arguments

  • self - The BitArray to read from
  • length - The bit length of the word to read, max 256

Returns

Option<u256> - If there are length bits remaining, the word is returned as u256

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::read_word_be_u256

fn read_word_be_u256(ref self: BitArray, length: u32) -> Option<u256>

read_word_be_u512

Reads a single word of the specified length up to 512 bits in big endian representation. For words shorter than (or equal to) 256 bits consider the other read calls instead.

Arguments

  • self - The BitArray to read from
  • length - The bit length of the word to read, max 512

Returns

Option<u512> - If there are length bits remaining, the word is returned as u512

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::read_word_be_u512

fn read_word_be_u512(ref self: BitArray, length: u32) -> Option<u512>

write_word_be

Writes the bits of the specified length from word onto the BitArray in big endian representation

Arguments

  • self - The BitArray to write to
  • word - The value to store onto the bit array of type felt252
  • length - The length of the word in bits, maximum 248

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::write_word_be

fn write_word_be(ref self: BitArray, word: felt252, length: u32)

write_word_be_u256

Writes the bits of the specified length from word onto the BitArray in big endian representation

Arguments

  • self - The BitArray to write to
  • word - The value to store onto the bit array of type u256
  • length - The length of the word in bits, maximum 256

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::write_word_be_u256

fn write_word_be_u256(ref self: BitArray, word: u256, length: u32)

write_word_be_u512

Writes the bits of the specified length from word onto the BitArray in big endian representation

Arguments

  • self - The BitArray to write to
  • word - The value to store onto the bit array of type u512
  • length - The length of the word in bits, maximum 512

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::write_word_be_u512

fn write_word_be_u512(ref self: BitArray, word: u512, length: u32)

read_word_le

Reads a single word of the specified length up to 248 bits in little endian bit representation

Arguments

  • self - The BitArray to read from
  • length - The bit length of the word to read, max 248

Returns

Option<felt252> - If there are length bits remaining, the word is returned as felt252

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::read_word_le

fn read_word_le(ref self: BitArray, length: u32) -> Option<felt252>

read_word_le_u256

Reads a single word of the specified length up to 256 bits in little endian representation. For words shorter than (or equal to) 248 bits use read_word_be(...) instead.

Arguments

  • self - The BitArray to read from
  • length - The bit length of the word to read, max 256

Returns

Option<u256> - If there are length bits remaining, the word is returned as u256

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::read_word_le_u256

fn read_word_le_u256(ref self: BitArray, length: u32) -> Option<u256>

read_word_le_u512

Reads a single word of the specified length up to 512 bits in little endian representation. For words shorter than (or equal to) 256 bits consider the other read calls instead.

Arguments

  • self - The BitArray to read from
  • length - The bit length of the word to read, max 512

Returns

Option<u512> - If there are length bits remaining, the word is returned as u512

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::read_word_le_u512

fn read_word_le_u512(ref self: BitArray, length: u32) -> Option<u512>

write_word_le

Writes the bits of the specified length from word onto the BitArray in little endian representation

Arguments

  • self - The BitArray to write to
  • word - The value to store onto the bit array of type felt252
  • length - The length of the word in bits, maximum 248

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::write_word_le

fn write_word_le(ref self: BitArray, word: felt252, length: u32)

write_word_le_u256

Writes the bits of the specified length from word onto the BitArray in little endian representation

Arguments

  • self - The BitArray to write to
  • word - The value to store onto the bit array of type u256
  • length - The length of the word in bits, maximum 256

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::write_word_le_u256

fn write_word_le_u256(ref self: BitArray, word: u256, length: u32)

write_word_le_u512

Writes the bits of the specified length from word onto the BitArray in little endian representation

Arguments

  • self - The BitArray to write to
  • word - The value to store onto the bit array of type u512
  • length - The length of the word in bits, maximum 512

Fully qualified path: alexandria_bytes::bit_array::BitArrayTrait::write_word_le_u512

fn write_word_le_u512(ref self: BitArray, word: u512, length: u32)

byte_appender

Fully qualified path: alexandria_bytes::byte_appender

Traits

ByteAppenderSupportTraitGeneric support trait for appending signed and unsigned integers onto byte storage. There are two functions, one for each of big and little endian byte order due to…
ByteAppender

Traits

Traits

ByteAppenderSupportTraitGeneric support trait for appending signed and unsigned integers onto byte storage. There are two functions, one for each of big and little endian byte order due to…
ByteAppender

ByteAppenderSupportTrait

Generic support trait for appending signed and unsigned integers onto byte storage. There are two functions, one for each of big and little endian byte order due to performance considerations. The byte reversal could be used in the naïve case when only one implementation is worthwhile.

Fully qualified path: alexandria_bytes::byte_appender::ByteAppenderSupportTrait

pub trait ByteAppenderSupportTrait<T>

Trait functions

append_bytes_be

Appends bytes data of size count ordered in big endian

Arguments

  • bytes - big endian ordered bytes to append
  • count - number of bytes from input to append

Fully qualified path: alexandria_bytes::byte_appender::ByteAppenderSupportTrait::append_bytes_be

fn append_bytes_be(ref self: T, bytes: felt252, count: u32)

append_bytes_le

Appends bytes data of size count ordered in little endian

Arguments

  • bytes - little endian ordered bytes to append
  • count - number of bytes from input to append

Fully qualified path: alexandria_bytes::byte_appender::ByteAppenderSupportTrait::append_bytes_le

fn append_bytes_le(ref self: T, bytes: felt252, count: u32)

ByteAppender

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender

pub trait ByteAppender<T>

Trait functions

append_u16

Appends an unsigned 16 bit integer encoded in big endian

Arguments

  • word - a 16 bit unsigned integer typed as u16

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_u16

fn append_u16(ref self: T, word: u16)

append_u16_le

Appends an unsigned 16 bit integer encoded in little endian

Arguments

  • word - a 16 bit unsigned integer typed as u16

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_u16_le

fn append_u16_le(ref self: T, word: u16)

append_u32

Appends an unsigned 32 bit integer encoded in big endian

Arguments

  • word - a 32 bit unsigned integer typed as u32

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_u32

fn append_u32(ref self: T, word: u32)

append_u32_le

Appends an unsigned 32 bit integer encoded in little endian

Arguments

  • word - a 32 bit unsigned integer typed as u32

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_u32_le

fn append_u32_le(ref self: T, word: u32)

append_u64

Appends an unsigned 64 bit integer encoded in big endian

Arguments

  • word - a 64 bit unsigned integer typed as u64

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_u64

fn append_u64(ref self: T, word: u64)

append_u64_le

Appends an unsigned 64 bit integer encoded in little endian

Arguments

  • word - a 64 bit unsigned integer typed as u64

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_u64_le

fn append_u64_le(ref self: T, word: u64)

append_u128

Appends an unsigned 128 bit integer encoded in big endian

Arguments

  • word - a 128 bit unsigned integer typed as u128

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_u128

fn append_u128(ref self: T, word: u128)

append_u128_le

Appends an unsigned 128 bit integer encoded in little endian

Arguments

  • word - a 128 bit unsigned integer typed as u128

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_u128_le

fn append_u128_le(ref self: T, word: u128)

append_u256

Appends an unsigned 256 bit integer encoded in big endian

Arguments

  • word - a 256 bit unsigned integer typed as u256

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_u256

fn append_u256(ref self: T, word: u256)

append_u256_le

Appends an unsigned 256 bit integer encoded in little endian

Arguments

  • word - a 256 bit unsigned integer typed as u256

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_u256_le

fn append_u256_le(ref self: T, word: u256)

append_u512

Appends an unsigned 512 bit integer encoded in big endian

Arguments

  • word - a 512 bit unsigned integer typed as u512

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_u512

fn append_u512(ref self: T, word: u512)

append_u512_le

Appends an unsigned 512 bit integer encoded in little endian

Arguments

  • word - a 512 bit unsigned integer typed as u512

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_u512_le

fn append_u512_le(ref self: T, word: u512)

append_i8

Appends a signed 8 bit integer

Arguments

  • word - an 8 bit signed integer typed as i8

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_i8

fn append_i8(ref self: T, word: i8)

append_i16

Appends a signed 16 bit integer encoded in big endian

Arguments

  • word - a 16 bit signed integer typed as i16

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_i16

fn append_i16(ref self: T, word: i16)

append_i16_le

Appends a signed 16 bit integer encoded in little endian

Arguments

  • word - a 16 bit signed integer typed as i16

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_i16_le

fn append_i16_le(ref self: T, word: i16)

append_i32

Appends a signed 32 bit integer encoded in big endian

Arguments

  • word - a 32 bit signed integer typed as i32

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_i32

fn append_i32(ref self: T, word: i32)

append_i32_le

Appends a signed 32 bit integer encoded in little endian

Arguments

  • word - a 32 bit signed integer typed as i32

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_i32_le

fn append_i32_le(ref self: T, word: i32)

append_i64

Appends a signed 64 bit integer encoded in big endian

Arguments

  • word - a 64 bit signed integer typed as i64

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_i64

fn append_i64(ref self: T, word: i64)

append_i64_le

Appends a signed 64 bit integer encoded in little endian

Arguments

  • word - a 64 bit signed integer typed as i64

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_i64_le

fn append_i64_le(ref self: T, word: i64)

append_i128

Appends a signed 128 bit integer encoded in big endian

Arguments

  • word - a 128 bit signed integer typed as i128

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_i128

fn append_i128(ref self: T, word: i128)

append_i128_le

Appends a signed 128 bit integer encoded in little endian

Arguments

  • word - a 128 bit signed integer typed as i128

Fully qualified path: alexandria_bytes::byte_appender::ByteAppender::append_i128_le

fn append_i128_le(ref self: T, word: i128)

byte_array_ext

Fully qualified path: alexandria_bytes::byte_array_ext

Traits

ByteArrayTraitExtExtension trait for reading and writing different data types to ByteArray

Impls

SpanU8IntoByteArrayImplementation for converting a Span to a ByteArray This conversion creates a new ByteArray by iterating through each byte…
ByteArrayIntoArrayU8Implementation for converting a ByteArray to an Array This conversion creates a new Array by iterating through each byte in the ByteArray and appending it to the array. This is useful when you need…
ByteArrayTraitExtImpl
ByteArrayAppenderImpl

Traits

Traits

ByteArrayTraitExtExtension trait for reading and writing different data types to ByteArray

ByteArrayTraitExt

Extension trait for reading and writing different data types to ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt

pub trait ByteArrayTraitExt

Trait functions

new

Create a ByteArray from an array of u128

Arguments

  • data - Array of u128 values to create ByteArray from

Returns

  • ByteArray - A new ByteArray created from the input data

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::new

fn new(data: Array<u128>) -> ByteArray

new_empty

instantiate a new ByteArray

Returns

  • ByteArray - A new empty ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::new_empty

fn new_empty() -> ByteArray

size

Arguments

  • self - The ByteArray to get the size of

Returns

  • usize - The size of the ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::size

fn size(self: @ByteArray) -> u32

read_u8

Reads a 8-bit unsigned integer from the given offset.

Arguments

  • self - The ByteArray to read from
  • offset - The offset to read from

Returns

  • (usize, u8) - The new offset and the u8 value read

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::read_u8

fn read_u8(self: @ByteArray, offset: u32) -> (u32, u8)

read_u16

Reads a 16-bit unsigned integer from the given offset.

Arguments

  • self - The ByteArray to read from
  • offset - The offset to read from

Returns

  • (usize, u16) - The new offset and the u16 value read

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::read_u16

fn read_u16(self: @ByteArray, offset: u32) -> (u32, u16)

read_u32

Reads a 32-bit unsigned integer from the given offset.

Arguments

  • self - The ByteArray to read from
  • offset - The offset to read from

Returns

  • (usize, u32) - The new offset and the u32 value read

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::read_u32

fn read_u32(self: @ByteArray, offset: u32) -> (u32, u32)

read_usize

Reads a usize from the given offset.

Arguments

  • self - The ByteArray to read from
  • offset - The offset to read from

Returns

  • (usize, usize) - The new offset and the usize value read

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::read_usize

fn read_usize(self: @ByteArray, offset: u32) -> (u32, u32)

read_u64

Reads a 64-bit unsigned integer from the given offset.

Arguments

  • self - The ByteArray to read from
  • offset - The offset to read from

Returns

  • (usize, u64) - The new offset and the u64 value read

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::read_u64

fn read_u64(self: @ByteArray, offset: u32) -> (u32, u64)

read_u128

Reads a 128-bit unsigned integer from the given offset.

Arguments

  • self - The ByteArray to read from
  • offset - The offset to read from

Returns

  • (usize, u128) - The new offset and the u128 value read

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::read_u128

fn read_u128(self: @ByteArray, offset: u32) -> (u32, u128)

read_u128_packed

Read value with size bytes from ByteArray, and packed into u128

Arguments

  • self - The ByteArray to read from
  • offset - The offset to read from
  • size - The number of bytes to read

Returns

  • (usize, u128) - The new offset and the packed u128 value

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::read_u128_packed

fn read_u128_packed(self: @ByteArray, offset: u32, size: u32) -> (u32, u128)

read_u128_array_packed

Reads a packed array of u128 values from the given offset.

Arguments

  • self - The ByteArray to read from
  • offset - The offset to read from
  • array_length - The length of the array to read
  • element_size - The size of each element in bytes

Returns

  • (usize, Array<u128>) - The new offset and the array of u128 values

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::read_u128_array_packed

fn read_u128_array_packed(
    self: @ByteArray, offset: u32, array_length: u32, element_size: u32,
) -> (u32, Array<u128>)

read_u256

Reads a 256-bit unsigned integer from the given offset.

Arguments

  • self - The ByteArray to read from
  • offset - The offset to read from

Returns

  • (usize, u256) - The new offset and the u256 value read

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::read_u256

fn read_u256(self: @ByteArray, offset: u32) -> (u32, u256)

read_u256_array

Reads an array of u256 values from the given offset.

Arguments

  • self - The ByteArray to read from
  • offset - The offset to read from
  • array_length - The length of the array to read

Returns

  • (usize, Array<u256>) - The new offset and the array of u256 values

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::read_u256_array

fn read_u256_array(self: @ByteArray, offset: u32, array_length: u32) -> (u32, Array<u256>)

read_felt252

Reads a felt252 (Starknet field element) from the given offset.

Arguments

  • self - The ByteArray to read from
  • offset - The offset to read from

Returns

  • (usize, felt252) - The new offset and the felt252 value read

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::read_felt252

fn read_felt252(self: @ByteArray, offset: u32) -> (u32, felt252)

read_felt252_packed

Read value with size bytes from Bytes, and packed into felt252

Arguments

  • self - The ByteArray to read from
  • offset - The offset to read from
  • size - The number of bytes to read

Returns

  • (usize, felt252) - The new offset and the packed felt252 value

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::read_felt252_packed

fn read_felt252_packed(self: @ByteArray, offset: u32, size: u32) -> (u32, felt252)

read_bytes31

Reads a bytes31 value (31-byte sequence) from the given offset.

Arguments

  • self - The ByteArray to read from
  • offset - The offset to read from

Returns

  • (usize, bytes31) - The new offset and the bytes31 value read

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::read_bytes31

fn read_bytes31(self: @ByteArray, offset: u32) -> (u32, bytes31)

read_address

Reads a Starknet contract address from the given offset.

Arguments

  • self - The ByteArray to read from
  • offset - The offset to read from

Returns

  • (usize, ContractAddress) - The new offset and the contract address

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::read_address

fn read_address(self: @ByteArray, offset: u32) -> (u32, ContractAddress)

read_bytes

Reads a raw sequence of bytes of given size from the given offset.

Arguments

  • self - The ByteArray to read from
  • offset - The offset to read from
  • size - The number of bytes to read

Returns

  • (usize, ByteArray) - The new offset and the read bytes as ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::read_bytes

fn read_bytes(self: @ByteArray, offset: u32, size: u32) -> (u32, ByteArray)

append_u8

Appends a 8-bit unsigned integer to the ByteArray.

Arguments

  • self - The ByteArray to append to
  • value - The value to append

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::append_u8

fn append_u8(ref self: ByteArray, value: u8)

append_u16

Appends a 16-bit unsigned integer to the ByteArray.

Arguments

  • self - The ByteArray to append to
  • value - The value to append

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::append_u16

fn append_u16(ref self: ByteArray, value: u16)

append_u16_le

Appends a 16-bit unsigned integer to the ByteArray in little-endian format.

Arguments

  • self - The ByteArray to append to
  • value - The value to append

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::append_u16_le

fn append_u16_le(ref self: ByteArray, value: u16)

append_u32

Appends a 32-bit unsigned integer to the ByteArray.

Arguments

  • self - The ByteArray to append to
  • value - The value to append

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::append_u32

fn append_u32(ref self: ByteArray, value: u32)

append_u32_le

Appends a 32-bit unsigned integer to the ByteArray in little-endian format.

Arguments

  • self - The ByteArray to append to
  • value - The value to append

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::append_u32_le

fn append_u32_le(ref self: ByteArray, value: u32)

append_usize

Appends usize to the ByteArray.

Arguments

  • self - The ByteArray to append to
  • value - The value to append

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::append_usize

fn append_usize(ref self: ByteArray, value: u32)

append_u64

Appends a 64-bit unsigned integer to the ByteArray.

Arguments

  • self - The ByteArray to append to
  • value - The value to append

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::append_u64

fn append_u64(ref self: ByteArray, value: u64)

append_u64_le

Appends a 64-bit unsigned integer to the ByteArray in little-endian format.

Arguments

  • self - The ByteArray to append to
  • value - The value to append

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::append_u64_le

fn append_u64_le(ref self: ByteArray, value: u64)

append_u128

Appends a 128-bit unsigned integer to the ByteArray.

Arguments

  • self - The ByteArray to append to
  • value - The value to append

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::append_u128

fn append_u128(ref self: ByteArray, value: u128)

append_u128_le

Appends a 128-bit unsigned integer to the ByteArray in little-endian format.

Arguments

  • self - The ByteArray to append to
  • value - The value to append

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::append_u128_le

fn append_u128_le(ref self: ByteArray, value: u128)

append_u256

Appends a 256-bit unsigned integer to the ByteArray.

Arguments

  • self - The ByteArray to append to
  • value - The value to append

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::append_u256

fn append_u256(ref self: ByteArray, value: u256)

append_u256_le

Appends a 256-bit unsigned integer to the ByteArray in little-endian format.

Arguments

  • self - The ByteArray to append to
  • value - The value to append

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::append_u256_le

fn append_u256_le(ref self: ByteArray, value: u256)

append_u512

Appends a 512-bit unsigned integer to the ByteArray.

Arguments

  • self - The ByteArray to append to
  • value - The value to append

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::append_u512

fn append_u512(ref self: ByteArray, value: u512)

append_felt252

Appends a felt252 to the ByteArray.

Arguments

  • self - The ByteArray to append to
  • value - The value to append

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::append_felt252

fn append_felt252(ref self: ByteArray, value: felt252)

append_bytes_le

Appends bytes data of size count ordered in little endian

Arguments

  • bytes - little endian ordered bytes to append
  • count - number of bytes from input to append

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::append_bytes_le

fn append_bytes_le(ref self: ByteArray, bytes: felt252, count: u32)

append_address

Appends a Starknet contract address to the ByteArray.

Arguments

  • self - The ByteArray to append to
  • value - The value to append

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::append_address

fn append_address(ref self: ByteArray, value: ContractAddress)

append_bytes31

Appends a bytes31 value to the ByteArray.

Arguments

  • self - The ByteArray to append to
  • value - The value to append

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::append_bytes31

fn append_bytes31(ref self: ByteArray, value: bytes31)

update_at

Updates a byte at the given offset with a new value.

Arguments

  • self - The ByteArray to update
  • offset - The offset to update at
  • value - The new value

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::update_at

fn update_at(ref self: ByteArray, offset: u32, value: u8)

read_uint_within_size

Reads an unsigned integer of type T from the ByteArray starting at a given offset, with a specified size.

Arguments

  • self - The ByteArray to read from
  • offset - The offset to read from
  • size - The number of bytes to read

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::read_uint_within_size

fn read_uint_within_size<
    T, +Add<T>, +Mul<T>, +Zero<T>, +TryInto<felt252, T>, +Drop<T>, +Into<u8, T>,
>(
    self: @ByteArray, offset: u32, size: u32,
) -> (u32, T)

keccak_be

Computes the keccak256 hash of the ByteArray in big-endian format.

Arguments

  • self - The ByteArray to compute keccak for

Returns

  • u256 - The keccak256 hash

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::keccak_be

fn keccak_be(self: @ByteArray) -> u256

keccak_le

Computes the keccak256 hash of the ByteArray in little-endian format.

Arguments

  • self - The ByteArray to compute keccak for

Returns

  • u256 - The keccak256 hash

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExt::keccak_le

fn keccak_le(self: @ByteArray) -> u256

Impls

Impls

SpanU8IntoByteArrayImplementation for converting a Span to a ByteArray This conversion creates a new ByteArray by iterating through each byte…
ByteArrayIntoArrayU8Implementation for converting a ByteArray to an Array This conversion creates a new Array by iterating through each byte in the ByteArray and appending it to the array. This is useful when you need…
ByteArrayTraitExtImpl
ByteArrayAppenderImpl

SpanU8IntoByteArray

Implementation for converting a Span to a ByteArray

This conversion creates a new ByteArray by iterating through each byte in the span and appending it to the ByteArray. This is useful for converting byte spans to the more efficient ByteArray representation.

Arguments

  • self - The Span to convert to ByteArray

Returns

  • ByteArray - A new ByteArray containing all bytes from the input span

Fully qualified path: alexandria_bytes::byte_array_ext::SpanU8IntoByteArray

pub impl SpanU8IntoByteArray of Into<Span<u8>, ByteArray>;

Impl functions

into

Fully qualified path: alexandria_bytes::byte_array_ext::SpanU8IntoByteArray::into

fn into(self: Span<u8>) -> ByteArray

ByteArrayIntoArrayU8

Implementation for converting a ByteArray to an Array

This conversion creates a new Array by iterating through each byte in the ByteArray and appending it to the array. This is useful when you need to work with individual bytes or interface with functions that expect Array.

Arguments

  • self - The ByteArray to convert to Array

Returns

  • Array<u8> - A new Array containing all bytes from the input ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayIntoArrayU8

pub impl ByteArrayIntoArrayU8 of Into<ByteArray, Array<u8>>;

Impl functions

into

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayIntoArrayU8::into

fn into(self: ByteArray) -> Array<u8>

ByteArrayTraitExtImpl

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl

pub impl ByteArrayTraitExtImpl of ByteArrayTraitExt;

Impl functions

new

Create a ByteArray from an array of u128

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::new

fn new(mut data: Array<u128>) -> ByteArray

new_empty

instantiate a new ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::new_empty

fn new_empty() -> ByteArray

size

get size. Same as len()

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::size

fn size(self: @ByteArray) -> u32

read_u8

Read a u8 from ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::read_u8

fn read_u8(self: @ByteArray, offset: u32) -> (u32, u8)

read_u16

Read a u16 from ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::read_u16

fn read_u16(self: @ByteArray, offset: u32) -> (u32, u16)

read_u32

Read a u32 from ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::read_u32

fn read_u32(self: @ByteArray, offset: u32) -> (u32, u32)

read_usize

Read a usize from ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::read_usize

fn read_usize(self: @ByteArray, offset: u32) -> (u32, u32)

read_u64

Read a u64 from ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::read_u64

fn read_u64(self: @ByteArray, offset: u32) -> (u32, u64)

read_u128

Read a u128 from ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::read_u128

fn read_u128(self: @ByteArray, offset: u32) -> (u32, u128)

read_u128_packed

Read value with size bytes from ByteArray, and packed into u128

Arguments:

  • offset: the offset in Bytes
  • size: the number of bytes to read

Returns:

  • new_offset: next value offset in Bytes
  • value: the value packed into u128

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::read_u128_packed

fn read_u128_packed(self: @ByteArray, offset: u32, size: u32) -> (u32, u128)

read_u256

Read a u256 from ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::read_u256

fn read_u256(self: @ByteArray, offset: u32) -> (u32, u256)

read_felt252_packed

Read value with size bytes from ByteArray, and packed into felt252

Arguments:

  • offset: the offset in Bytes
  • size: the number of bytes to read

Returns:

  • new_offset: next value offset in Bytes
  • value: the value packed into felt252

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::read_felt252_packed

fn read_felt252_packed(self: @ByteArray, offset: u32, size: u32) -> (u32, felt252)

read_felt252

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::read_felt252

fn read_felt252(self: @ByteArray, offset: u32) -> (u32, felt252)

read_bytes31

Read a bytes31 from ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::read_bytes31

fn read_bytes31(self: @ByteArray, offset: u32) -> (u32, bytes31)

read_address

Read Contract Address from Bytes

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::read_address

fn read_address(self: @ByteArray, offset: u32) -> (u32, ContractAddress)

read_bytes

Read bytes from ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::read_bytes

fn read_bytes(self: @ByteArray, offset: u32, size: u32) -> (u32, ByteArray)

read_u128_array_packed

Read an array of u128 values from ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::read_u128_array_packed

fn read_u128_array_packed(
    self: @ByteArray, offset: u32, array_length: u32, element_size: u32,
) -> (u32, Array<u128>)

read_u256_array

Read an array of u256 values from ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::read_u256_array

fn read_u256_array(self: @ByteArray, offset: u32, array_length: u32) -> (u32, Array<u256>)

read_uint_within_size

Reads an unsigned integer of type T from the ByteArray starting at a given offset, with a specified size.

Inputs:

  • self: A reference to the ByteArray from which to read.
  • offset: The starting position in the ByteArray to begin reading.
  • size: The number of bytes to read.

Outputs:

  • A tuple containing:
    • The new offset after reading the specified number of bytes.
    • The value of type T read from the ByteArray.

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::read_uint_within_size

fn read_uint_within_size(self: @ByteArray, offset: u32, size: u32) -> (u32, T)

append_u8

Append a u8 to ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::append_u8

fn append_u8(ref self: ByteArray, value: u8)

append_u16

Append a u16 to ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::append_u16

fn append_u16(ref self: ByteArray, value: u16)

append_u16_le

Append a u16 to ByteArray in little-endian format

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::append_u16_le

fn append_u16_le(ref self: ByteArray, value: u16)

append_u32

Append a u32 to ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::append_u32

fn append_u32(ref self: ByteArray, value: u32)

append_u32_le

Append a u32 to ByteArray in little-endian format

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::append_u32_le

fn append_u32_le(ref self: ByteArray, value: u32)

append_usize

Append a usize to ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::append_usize

fn append_usize(ref self: ByteArray, value: u32)

append_u64

Append a u64 to ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::append_u64

fn append_u64(ref self: ByteArray, value: u64)

append_u64_le

Append a u64 to ByteArray in little-endian format

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::append_u64_le

fn append_u64_le(ref self: ByteArray, value: u64)

append_u128

Append a u128 to ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::append_u128

fn append_u128(ref self: ByteArray, value: u128)

append_u128_le

Append a u128 to ByteArray in little-endian format

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::append_u128_le

fn append_u128_le(ref self: ByteArray, value: u128)

append_u256

Append a u256 to ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::append_u256

fn append_u256(ref self: ByteArray, value: u256)

append_u256_le

Append a u256 to ByteArray in little-endian format

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::append_u256_le

fn append_u256_le(ref self: ByteArray, value: u256)

append_u512

Append a u512 to ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::append_u512

fn append_u512(ref self: ByteArray, value: u512)

append_felt252

Append a felt252 to ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::append_felt252

fn append_felt252(ref self: ByteArray, value: felt252)

append_bytes_le

Append bytes data of size count ordered in little endian

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::append_bytes_le

fn append_bytes_le(ref self: ByteArray, bytes: felt252, count: u32)

append_address

Append a ContractAddress to ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::append_address

fn append_address(ref self: ByteArray, value: ContractAddress)

append_bytes31

Append a bytes31 to ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::append_bytes31

fn append_bytes31(ref self: ByteArray, value: bytes31)

update_at

Update a byte at a specific offset in ByteArray

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::update_at

fn update_at(ref self: ByteArray, offset: u32, value: u8)

keccak_be

Computes the keccak256 hash of the ByteArray in big-endian format

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::keccak_be

fn keccak_be(self: @ByteArray) -> u256

keccak_le

Computes the keccak256 hash of the ByteArray in little-endian format

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayTraitExtImpl::keccak_le

fn keccak_le(self: @ByteArray) -> u256

ByteArrayAppenderImpl

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl

pub impl ByteArrayAppenderImpl of ByteAppender<ByteArray>;

Impl functions

append_u16

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_u16

fn append_u16(ref self: ByteArray, word: u16)

append_u16_le

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_u16_le

fn append_u16_le(ref self: ByteArray, word: u16)

append_u32

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_u32

fn append_u32(ref self: ByteArray, word: u32)

append_u32_le

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_u32_le

fn append_u32_le(ref self: ByteArray, word: u32)

append_u64

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_u64

fn append_u64(ref self: ByteArray, word: u64)

append_u64_le

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_u64_le

fn append_u64_le(ref self: ByteArray, word: u64)

append_u128

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_u128

fn append_u128(ref self: ByteArray, word: u128)

append_u128_le

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_u128_le

fn append_u128_le(ref self: ByteArray, word: u128)

append_u256

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_u256

fn append_u256(ref self: ByteArray, word: u256)

append_u256_le

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_u256_le

fn append_u256_le(ref self: ByteArray, word: u256)

append_u512

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_u512

fn append_u512(ref self: ByteArray, word: u512)

append_u512_le

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_u512_le

fn append_u512_le(ref self: ByteArray, word: u512)

append_i8

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_i8

fn append_i8(ref self: ByteArray, word: i8)

append_i16

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_i16

fn append_i16(ref self: ByteArray, word: i16)

append_i16_le

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_i16_le

fn append_i16_le(ref self: ByteArray, word: i16)

append_i32

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_i32

fn append_i32(ref self: ByteArray, word: i32)

append_i32_le

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_i32_le

fn append_i32_le(ref self: ByteArray, word: i32)

append_i64

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_i64

fn append_i64(ref self: ByteArray, word: i64)

append_i64_le

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_i64_le

fn append_i64_le(ref self: ByteArray, word: i64)

append_i128

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_i128

fn append_i128(ref self: ByteArray, word: i128)

append_i128_le

Fully qualified path: alexandria_bytes::byte_array_ext::ByteArrayAppenderImpl::append_i128_le

fn append_i128_le(ref self: ByteArray, word: i128)

byte_reader

Fully qualified path: alexandria_bytes::byte_reader

Structs

ByteReaderStateRepresents the state of a byte reader for sequential reading operations….

Traits

Structs

Structs

ByteReaderStateRepresents the state of a byte reader for sequential reading operations….

ByteReaderState

Represents the state of a byte reader for sequential reading operations.

Fields

  • data - A snapshot reference to the underlying data structure
  • index - The current position in the data for reading operations

Fully qualified path: alexandria_bytes::byte_reader::ByteReaderState

[derive(Clone, Drop)]
pub struct ByteReaderState<T> { /* private fields */ }

Traits

Traits

ByteReader

Fully qualified path: alexandria_bytes::byte_reader::ByteReader

pub trait ByteReader<T>

Trait functions

reader

Wraps the array of bytes in a ByteReader for sequential consumption of integers and/or bytes

Returns

  • ByteReader - The reader struct wrapping a read-only snapshot of this ByteArray

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::reader

fn reader(self: @T) -> ByteReaderState<T>

remaining

Checks that there are enough remaining bytes available

Arguments

  • at - the start index position of the byte data
  • count - the number of bytes required

Returns

  • bool - true when there are count bytes remaining, false otherwise.

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::remaining

fn remaining(self: @T, at: u32, count: u32) -> bool

word_u16

Reads consecutive bytes from a specified offset as an unsigned integer in big endian

Arguments

  • offset - the start location of the consecutive bytes to read

Returns

  • Option<u16> - Returns an integer if there are enough consecutive bytes available in the ByteArray

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::word_u16

fn word_u16(self: @T, offset: u32) -> Option<u16>

word_u16_le

Reads consecutive bytes from a specified offset as an unsigned integer in little endian

Arguments

  • offset - the start location of the consecutive bytes to read

Returns

  • Option<u16> - Returns an integer if there are enough consecutive bytes available in the ByteArray

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::word_u16_le

fn word_u16_le(self: @T, offset: u32) -> Option<u16>

word_u32

Reads consecutive bytes from a specified offset as an unsigned integer in big endian

Arguments

  • offset - the start location of the consecutive bytes to read

Returns

  • Option<u32> - Returns an integer if there are enough consecutive bytes available in the ByteArray

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::word_u32

fn word_u32(self: @T, offset: u32) -> Option<u32>

word_u32_le

Reads consecutive bytes from a specified offset as an unsigned integer in little endian

Arguments

  • offset - the start location of the consecutive bytes to read

Returns

  • Option<u32> - Returns an integer if there are enough consecutive bytes available in the ByteArray

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::word_u32_le

fn word_u32_le(self: @T, offset: u32) -> Option<u32>

word_u64

Reads consecutive bytes from a specified offset as an unsigned integer in big endian

Arguments

  • offset - the start location of the consecutive bytes to read

Returns

  • Option<u64> - Returns an integer if there are enough consecutive bytes available in the ByteArray

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::word_u64

fn word_u64(self: @T, offset: u32) -> Option<u64>

word_u64_le

Reads consecutive bytes from a specified offset as an unsigned integer in little endian

Arguments

  • offset - the start location of the consecutive bytes to read

Returns

  • Option<u64> - Returns an integer if there are enough consecutive bytes available in the ByteArray

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::word_u64_le

fn word_u64_le(self: @T, offset: u32) -> Option<u64>

word_u128

Reads consecutive bytes from a specified offset as an unsigned integer in big endian

Arguments

  • offset - the start location of the consecutive bytes to read

Returns

  • Option<u128> - Returns an integer if there are enough consecutive bytes available in the ByteArray

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::word_u128

fn word_u128(self: @T, offset: u32) -> Option<u128>

word_u128_le

Reads consecutive bytes from a specified offset as an unsigned integer in little endian

Arguments

  • offset - the start location of the consecutive bytes to read

Returns

  • Option<u128> - Returns an integer if there are enough consecutive bytes available in the ByteArray

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::word_u128_le

fn word_u128_le(self: @T, offset: u32) -> Option<u128>

read_u8

Reads a u8 unsigned integer

Returns

  • Option<u8> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_u8

fn read_u8(ref self: ByteReaderState<T>) -> Option<u8>

read_u16

Reads a u16 unsigned integer in big endian byte order

Returns

  • Option<u16> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_u16

fn read_u16(ref self: ByteReaderState<T>) -> Option<u16>

read_u16_le

Reads a u16 unsigned integer in little endian byte order

Returns

  • Option<u16> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_u16_le

fn read_u16_le(ref self: ByteReaderState<T>) -> Option<u16>

read_u32

Reads a u32 unsigned integer in big endian byte order

Returns

  • Option<u32> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_u32

fn read_u32(ref self: ByteReaderState<T>) -> Option<u32>

read_u32_le

Reads a u32 unsigned integer in little endian byte order

Returns

  • Option<u32> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_u32_le

fn read_u32_le(ref self: ByteReaderState<T>) -> Option<u32>

read_u64

Reads a u64 unsigned integer in big endian byte order

Returns

  • Option<u64> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_u64

fn read_u64(ref self: ByteReaderState<T>) -> Option<u64>

read_u64_le

Reads a u64 unsigned integer in little endian byte order

Returns

  • Option<u64> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_u64_le

fn read_u64_le(ref self: ByteReaderState<T>) -> Option<u64>

read_u128

Reads a u128 unsigned integer in big endian byte order

Returns

  • Option<u128> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_u128

fn read_u128(ref self: ByteReaderState<T>) -> Option<u128>

read_u128_le

Reads a u128 unsigned integer in little endian byte order

Returns

  • Option<u128> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_u128_le

fn read_u128_le(ref self: ByteReaderState<T>) -> Option<u128>

read_u256

Reads a u256 unsigned integer in big endian byte order

Returns

  • Option<u256> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_u256

fn read_u256(ref self: ByteReaderState<T>) -> Option<u256>

read_u256_le

Reads a u256 unsigned integer in little endian byte order

Returns

  • Option<u256> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_u256_le

fn read_u256_le(ref self: ByteReaderState<T>) -> Option<u256>

read_u512

Reads a u512 unsigned integer in big endian byte order

Returns

  • Option<u512> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_u512

fn read_u512(ref self: ByteReaderState<T>) -> Option<u512>

read_u512_le

Reads a u512 unsigned integer in little endian byte order

Returns

  • Option<u512> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_u512_le

fn read_u512_le(ref self: ByteReaderState<T>) -> Option<u512>

read_i8

Reads an i8 signed integer in two’s complement encoding from the ByteArray

Returns

  • Option<i8> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_i8

fn read_i8(ref self: ByteReaderState<T>) -> Option<i8>

read_i16

Reads an i16 signed integer in two’s complement encoding from the ByteArray in big endian byte order

Returns

  • Option<i16> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_i16

fn read_i16(ref self: ByteReaderState<T>) -> Option<i16>

read_i16_le

Reads an i16 signed integer in two’s complement encoding from the ByteArray in little endian byte order

Returns

  • Option<i16> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_i16_le

fn read_i16_le(ref self: ByteReaderState<T>) -> Option<i16>

read_i32

Reads an i32 signed integer in two’s complement encoding from the ByteArray in big endian byte order

Returns

  • Option<i32> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_i32

fn read_i32(ref self: ByteReaderState<T>) -> Option<i32>

read_i32_le

Reads an i32 signed integer in two’s complement encoding from the ByteArray in little endian byte order

Returns

  • Option<i32> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_i32_le

fn read_i32_le(ref self: ByteReaderState<T>) -> Option<i32>

read_i64

Reads an i64 signed integer in two’s complement encoding from the ByteArray in big endian byte order

Returns

  • Option<i64> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_i64

fn read_i64(ref self: ByteReaderState<T>) -> Option<i64>

read_i64_le

Reads an i64 signed integer in two’s complement encoding from the ByteArray in little endian byte order

Returns

  • Option<i64> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_i64_le

fn read_i64_le(ref self: ByteReaderState<T>) -> Option<i64>

read_i128

Reads an i128 signed integer in two’s complement encoding from the ByteArray in big endian byte order

Returns

  • Option<i128> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_i128

fn read_i128(ref self: ByteReaderState<T>) -> Option<i128>

read_i128_le

Reads an i128 signed integer in two’s complement encoding from the ByteArray in little endian byte order

Returns

  • Option<i128> - If there are enough bytes remaining an optional integer is returned

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::read_i128_le

fn read_i128_le(ref self: ByteReaderState<T>) -> Option<i128>

len

Remaining length count relative to what has already been consume/read

Returns

  • usize - count number of bytes remaining

Fully qualified path: alexandria_bytes::byte_reader::ByteReader::len

fn len(self: @ByteReaderState<T>) -> u32

bytes

Fully qualified path: alexandria_bytes::bytes

Constants

BYTES_PER_ELEMENTBytes is a dynamic array of u128, where each element contains 16 bytes.

Structs

BytesNote that: In Bytes, there are many variables about size and length. We use size to represent the number of bytes in Bytes. We use length to represent the number of elements in Bytes….

Traits

Impls

BytesIndexImplementation of IndexView trait for Bytes. Allows indexing into the Bytes structure to access individual u128 elements.
ByteArrayIntoBytesImplementation for converting a ByteArray to a Bytes struct This conversion creates a new Bytes structure from a ByteArray by iterating…
BytesIntoByteArrayImplementation for converting a Bytes struct to a ByteArray This conversion efficiently transfers data from a Bytes structure to a ByteArray…

Constants

Constants

BYTES_PER_ELEMENTBytes is a dynamic array of u128, where each element contains 16 bytes.

BYTES_PER_ELEMENT

Bytes is a dynamic array of u128, where each element contains 16 bytes.

Fully qualified path: alexandria_bytes::bytes::BYTES_PER_ELEMENT

pub const BYTES_PER_ELEMENT: u32 = 16;

Structs

Structs

BytesNote that: In Bytes, there are many variables about size and length. We use size to represent the number of bytes in Bytes. We use length to represent the number of elements in Bytes….

Bytes

Note that: In Bytes, there are many variables about size and length. We use size to represent the number of bytes in Bytes. We use length to represent the number of elements in Bytes.

Bytes is a cairo implementation of solidity Bytes in Big-endian. It is a dynamic array of u128, where each element contains 16 bytes. To save cost, the last element MUST be filled fully. That means that every element should and MUST contain 16 bytes.

For example, if we have a Bytes with 33 bytes, we will have 3 elements. Theoretically, the bytes look like this: first element: 16 bytes second element: 16 bytes third element: 1 byte But in alexandria bytes, the last element should be padded with zero to make it 16 bytes. So the alexandria bytes look like this: first element: 16 bytes second element: 16 bytes third element: 1 byte + 15 bytes zero padding

Bytes is a dynamic array of u128, where each element contains 16 bytes.

  • size: the number of bytes in the Bytes
  • data: the data of the Bytes

Fully qualified path: alexandria_bytes::bytes::Bytes

[derive(Drop, Clone, PartialEq)]
pub struct Bytes { /* private fields */ }

Traits

Traits

BytesTrait

Fully qualified path: alexandria_bytes::bytes::BytesTrait

pub trait BytesTrait

Trait functions

new

Create a Bytes from an array of u128

Fully qualified path: alexandria_bytes::bytes::BytesTrait::new

fn new(size: u32, data: Array<u128>) -> Bytes

new_empty

Create an empty Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::new_empty

fn new_empty() -> Bytes

zero

Create a Bytes with size bytes 0

Fully qualified path: alexandria_bytes::bytes::BytesTrait::zero

fn zero(size: u32) -> Bytes

locate

Locate offset in Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::locate

fn locate(offset: u32) -> (u32, u32)

size

Get Bytes size

Fully qualified path: alexandria_bytes::bytes::BytesTrait::size

fn size(self: @Bytes) -> u32

data

Get data

Fully qualified path: alexandria_bytes::bytes::BytesTrait::data

fn data(self: Bytes) -> Array<u128>

update_at

update specific value (1 bytes) at specific offset

Fully qualified path: alexandria_bytes::bytes::BytesTrait::update_at

fn update_at(ref self: Bytes, offset: u32, value: u8)

read_u128_packed

Read value with size bytes from Bytes, and packed into u128

Fully qualified path: alexandria_bytes::bytes::BytesTrait::read_u128_packed

fn read_u128_packed(self: @Bytes, offset: u32, size: u32) -> (u32, u128)

read_u128_array_packed

Read value with element_size bytes from Bytes, and packed into u128 array

Fully qualified path: alexandria_bytes::bytes::BytesTrait::read_u128_array_packed

fn read_u128_array_packed(
    self: @Bytes, offset: u32, array_length: u32, element_size: u32,
) -> (u32, Array<u128>)

read_felt252_packed

Read value with size bytes from Bytes, and packed into felt252

Fully qualified path: alexandria_bytes::bytes::BytesTrait::read_felt252_packed

fn read_felt252_packed(self: @Bytes, offset: u32, size: u32) -> (u32, felt252)

read_u8

Read a u8 from Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::read_u8

fn read_u8(self: @Bytes, offset: u32) -> (u32, u8)

read_u16

Read a u16 from Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::read_u16

fn read_u16(self: @Bytes, offset: u32) -> (u32, u16)

read_u32

Read a u32 from Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::read_u32

fn read_u32(self: @Bytes, offset: u32) -> (u32, u32)

read_usize

Read a usize from Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::read_usize

fn read_usize(self: @Bytes, offset: u32) -> (u32, u32)

read_u64

Read a u64 from Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::read_u64

fn read_u64(self: @Bytes, offset: u32) -> (u32, u64)

read_u128

Read a u128 from Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::read_u128

fn read_u128(self: @Bytes, offset: u32) -> (u32, u128)

read_u256

Read a u256 from Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::read_u256

fn read_u256(self: @Bytes, offset: u32) -> (u32, u256)

read_u256_array

Read a u256 array from Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::read_u256_array

fn read_u256_array(self: @Bytes, offset: u32, array_length: u32) -> (u32, Array<u256>)

read_bytes

Read sub Bytes with size bytes from Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::read_bytes

fn read_bytes(self: @Bytes, offset: u32, size: u32) -> (u32, Bytes)

read_felt252

Read felt252 from Bytes, which stored as u256

Fully qualified path: alexandria_bytes::bytes::BytesTrait::read_felt252

fn read_felt252(self: @Bytes, offset: u32) -> (u32, felt252)

read_bytes31

Read bytes31 from Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::read_bytes31

fn read_bytes31(self: @Bytes, offset: u32) -> (u32, bytes31)

read_address

Read a ContractAddress from Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::read_address

fn read_address(self: @Bytes, offset: u32) -> (u32, ContractAddress)

append_u128_packed

Write value with size bytes into Bytes, value is packed into u128

Fully qualified path: alexandria_bytes::bytes::BytesTrait::append_u128_packed

fn append_u128_packed(ref self: Bytes, value: u128, size: u32)

append_u8

Write u8 into Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::append_u8

fn append_u8(ref self: Bytes, value: u8)

append_u16

Write u16 into Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::append_u16

fn append_u16(ref self: Bytes, value: u16)

append_u32

Write u32 into Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::append_u32

fn append_u32(ref self: Bytes, value: u32)

append_usize

Write usize into Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::append_usize

fn append_usize(ref self: Bytes, value: u32)

append_u64

Write u64 into Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::append_u64

fn append_u64(ref self: Bytes, value: u64)

append_u128

Write u128 into Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::append_u128

fn append_u128(ref self: Bytes, value: u128)

append_u256

Write u256 into Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::append_u256

fn append_u256(ref self: Bytes, value: u256)

append_felt252

Write felt252 into Bytes, which stored as u256

Fully qualified path: alexandria_bytes::bytes::BytesTrait::append_felt252

fn append_felt252(ref self: Bytes, value: felt252)

append_bytes31

Write bytes31 into Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::append_bytes31

fn append_bytes31(ref self: Bytes, value: bytes31)

append_address

Write address into Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::append_address

fn append_address(ref self: Bytes, value: ContractAddress)

concat

concat with other Bytes

Fully qualified path: alexandria_bytes::bytes::BytesTrait::concat

fn concat(ref self: Bytes, other: @Bytes)

keccak

keccak hash

Fully qualified path: alexandria_bytes::bytes::BytesTrait::keccak

fn keccak(self: @Bytes) -> u256

sha256

sha256 hash

Fully qualified path: alexandria_bytes::bytes::BytesTrait::sha256

fn sha256(self: @Bytes) -> u256

Impls

Impls

BytesIndexImplementation of IndexView trait for Bytes. Allows indexing into the Bytes structure to access individual u128 elements.
ByteArrayIntoBytesImplementation for converting a ByteArray to a Bytes struct This conversion creates a new Bytes structure from a ByteArray by iterating…
BytesIntoByteArrayImplementation for converting a Bytes struct to a ByteArray This conversion efficiently transfers data from a Bytes structure to a ByteArray…

BytesIndex

Implementation of IndexView trait for Bytes. Allows indexing into the Bytes structure to access individual u128 elements.

Fully qualified path: alexandria_bytes::bytes::BytesIndex

pub impl BytesIndex of IndexView<Bytes, u32>;

Impl functions

index

Fully qualified path: alexandria_bytes::bytes::BytesIndex::index

fn index(self: @Bytes, index: u32) -> @u128

Impl types

Target

Fully qualified path: alexandria_bytes::bytes::BytesIndex::Target

type Target = @u128;

ByteArrayIntoBytes

Implementation for converting a ByteArray to a Bytes struct

This conversion creates a new Bytes structure from a ByteArray by iterating through each byte in the ByteArray and appending it to the Bytes structure. The conversion preserves all data and maintains byte order.

Arguments

  • self - The ByteArray to convert to a Bytes struct

Returns

  • Bytes - A new Bytes struct containing all bytes from the input ByteArray

Fully qualified path: alexandria_bytes::bytes::ByteArrayIntoBytes

pub impl ByteArrayIntoBytes of Into<ByteArray, Bytes>;

Impl functions

into

Fully qualified path: alexandria_bytes::bytes::ByteArrayIntoBytes::into

fn into(self: ByteArray) -> Bytes

BytesIntoByteArray

Implementation for converting a Bytes struct to a ByteArray

This conversion efficiently transfers data from a Bytes structure to a ByteArray by reading data in optimal chunks (31-byte words when possible, single bytes otherwise). The conversion preserves all data and maintains byte order.

Arguments

  • self - The Bytes struct to convert to ByteArray

Returns

  • ByteArray - A new ByteArray containing all bytes from the input Bytes struct

Fully qualified path: alexandria_bytes::bytes::BytesIntoByteArray

pub impl BytesIntoByteArray of Into<Bytes, ByteArray>;

Impl functions

into

Fully qualified path: alexandria_bytes::bytes::BytesIntoByteArray::into

fn into(self: Bytes) -> ByteArray

reversible

Fully qualified path: alexandria_bytes::reversible

Free functions

reversingReverses the order of elements in a value by extracting and reassembling them This generic function reverses the ordering of elements within a value by repeatedly…
reversing_partial_resultReverses elements from a word onto an existing partial result This function extends the reversing operation by allowing it to build upon…

Traits

ReversibleBytesImplies that there is an underlying byte order for type T that can be reversed
ReversibleBitsImplies that there is an underlying bit order for type T that can be reversed

Free functions

Free functions

reversingReverses the order of elements in a value by extracting and reassembling them This generic function reverses the ordering of elements within a value by repeatedly…
reversing_partial_resultReverses elements from a word onto an existing partial result This function extends the reversing operation by allowing it to build upon…

reversing

Reverses the order of elements in a value by extracting and reassembling them

This generic function reverses the ordering of elements within a value by repeatedly dividing by a step size and building the result in reverse order. It’s commonly used for reversing bits or bytes within numeric types.

The step parameter MUST be a power of 2 (e.g., 2, 256, 65536). Using a non-power-of-2 step will produce incorrect results and data corruption. Valid steps: 2 (bits), 256 (bytes), 65536 (u16 words), etc.

Arguments

  • word - The value to reverse
  • size - The number of elements to reverse
  • step - The step size for each element (MUST be a power of 2: 2, 256, 65536, etc.)

Returns

  • (T, T) - A tuple containing (reversed_value, remaining_value)

Panics

  • If step is not a power of 2 (runtime check performed)

Fully qualified path: alexandria_bytes::reversible::reversing

pub fn reversing<
    T,
    +Copy<T>,
    +Zero<T>,
    +TryInto<T, NonZero<T>>,
    +Into<T, u128>,
    +TryInto<u128, T>,
    +DivRem<T>,
    +Drop<T>,
    +MulAssign<T, T>,
    +Rem<T>,
    +AddAssign<T, T>,
>(
    word: T, size: u32, step: T,
) -> (T, T)

reversing_partial_result

Reverses elements from a word onto an existing partial result

This function extends the reversing operation by allowing it to build upon an existing partial result. It extracts elements from the input word and appends them to the ongoing result, useful for multi-stage reversing operations.

The step parameter MUST be a power of 2 (e.g., 2, 256, 65536). Using a non-power-of-2 step will produce incorrect results and data corruption. Valid steps: 2 (bits), 256 (bytes), 65536 (u16 words), etc.

Arguments

  • word - The value to extract elements from for reversal
  • onto - The existing partial result to build upon
  • size - The number of elements to reverse and append
  • step - The step size for each element (MUST be a power of 2: 2, 256, 65536, etc.)

Returns

  • (T, T) - A tuple containing (final_result_with_appended_elements, remaining_word)

Panics

  • If step is not a power of 2 (runtime check performed)

Fully qualified path: alexandria_bytes::reversible::reversing_partial_result

pub fn reversing_partial_result<
    T,
    +Copy<T>,
    +DivRem<T>,
    +TryInto<T, NonZero<T>>,
    +Into<T, u128>,
    +TryInto<u128, T>,
    +Drop<T>,
    +MulAssign<T, T>,
    +Rem<T>,
    +AddAssign<T, T>,
>(
    mut word: T, mut onto: T, size: u32, step: T,
) -> (T, T)

Traits

Traits

ReversibleBytesImplies that there is an underlying byte order for type T that can be reversed
ReversibleBitsImplies that there is an underlying bit order for type T that can be reversed

ReversibleBytes

Implies that there is an underlying byte order for type T that can be reversed

Fully qualified path: alexandria_bytes::reversible::ReversibleBytes

pub trait ReversibleBytes<T>

Trait functions

reverse_bytes

Reverses the byte order or endianness of self. For example, the word 0x1122_u16 is reversed into 0x2211_u16.

Returns

  • T - returns the byte reversal of self into the same type T

Fully qualified path: alexandria_bytes::reversible::ReversibleBytes::reverse_bytes

fn reverse_bytes(self: @T) -> T

ReversibleBits

Implies that there is an underlying bit order for type T that can be reversed

Fully qualified path: alexandria_bytes::reversible::ReversibleBits

pub trait ReversibleBits<T>

Trait functions

reverse_bits

Reverses the underlying ordering of the bit representation of self. For example, the word 0b10111010_u8 is reversed into 0b01011101.

Returns

  • T - the bit-representation of self reversed into the same type T

Fully qualified path: alexandria_bytes::reversible::ReversibleBits::reverse_bits

fn reverse_bits(self: @T) -> T

storage

Fully qualified path: alexandria_bytes::storage

Impls

BytesStoreStore for a Bytes object. The layout of a Bytes object in storage is as follows:…

Impls

Impls

BytesStoreStore for a Bytes object. The layout of a Bytes object in storage is as follows:…

BytesStore

Store for a Bytes object.

The layout of a Bytes object in storage is as follows:

  • Only the size in bytes is stored in the original address where the bytes object is stored.
  • The actual data is stored in chunks of 256 u128 values in another location in storage determined by the hash of:
    • The address storing the size of the bytes object.
    • The chunk index.
    • The short string Bytes.

Fully qualified path: alexandria_bytes::storage::BytesStore

pub impl BytesStore of Store<Bytes>;

Impl functions

read

Fully qualified path: alexandria_bytes::storage::BytesStore::read

fn read(address_domain: u32, base: StorageBaseAddress) -> Result<Bytes, Array<felt252>>

write

Fully qualified path: alexandria_bytes::storage::BytesStore::write

fn write(address_domain: u32, base: StorageBaseAddress, value: Bytes) -> Result<(), Array<felt252>>

read_at_offset

Fully qualified path: alexandria_bytes::storage::BytesStore::read_at_offset

fn read_at_offset(
    address_domain: u32, base: StorageBaseAddress, offset: u8,
) -> Result<Bytes, Array<felt252>>

write_at_offset

Fully qualified path: alexandria_bytes::storage::BytesStore::write_at_offset

fn write_at_offset(
    address_domain: u32, base: StorageBaseAddress, offset: u8, value: Bytes,
) -> Result<(), Array<felt252>>

size

Fully qualified path: alexandria_bytes::storage::BytesStore::size

fn size() -> u8

utils

Fully qualified path: alexandria_bytes::utils

Free functions

keccak_u128s_beComputes the keccak256 of multiple uint128 values. The values are interpreted as big-endian. https://github.com/starkware-libs/cairo/blob/main/corelib/src/keccak.cairo…
u256_reverse_endianReverses the endianness of a u256 value….
u8_array_to_u256Convert sha256 result(Array ) to u256…
u32s_to_u256Converts an array of 8 u32 values to a u256 value….
u128_array_sliceReturns the slice of an array….
u128_splitSplit a u128 into two parts, 0, left_size-1 and left_size, end…
read_sub_u128Read sub value from u128 just like substr in other language…
u128_joinJoin two u128 into one…

Impls

BytesDebugImplementation of Debug trait for Bytes. Formats the Bytes as a hexadecimal string prefixed with “0x”.
BytesDisplayImplementation of Display trait for Bytes. Formats the Bytes as a hexadecimal string prefixed with “0x”.

Free functions

Free functions

keccak_u128s_beComputes the keccak256 of multiple uint128 values. The values are interpreted as big-endian. https://github.com/starkware-libs/cairo/blob/main/corelib/src/keccak.cairo…
u256_reverse_endianReverses the endianness of a u256 value….
u8_array_to_u256Convert sha256 result(Array ) to u256…
u32s_to_u256Converts an array of 8 u32 values to a u256 value….
u128_array_sliceReturns the slice of an array….
u128_splitSplit a u128 into two parts, 0, left_size-1 and left_size, end…
read_sub_u128Read sub value from u128 just like substr in other language…
u128_joinJoin two u128 into one…

keccak_u128s_be

Computes the keccak256 of multiple uint128 values. The values are interpreted as big-endian. https://github.com/starkware-libs/cairo/blob/main/corelib/src/keccak.cairo

Arguments

  • input - Span of u128 values to hash
  • n_bytes - Total number of bytes to process

Returns

  • u256 - The keccak256 hash

Fully qualified path: alexandria_bytes::utils::keccak_u128s_be

pub fn keccak_u128s_be(input: Span<u128>, n_bytes: u32) -> u256

u256_reverse_endian

Reverses the endianness of a u256 value.

Arguments

  • input - The u256 value to reverse endianness

Returns

  • u256 - The u256 value with reversed endianness

Fully qualified path: alexandria_bytes::utils::u256_reverse_endian

pub fn u256_reverse_endian(input: u256) -> u256

u8_array_to_u256

Convert sha256 result(Array) to u256

Arguments

  • arr - Span of u8 values, length MUST be 32

Returns

  • u256 - The converted u256 value

Fully qualified path: alexandria_bytes::utils::u8_array_to_u256

pub fn u8_array_to_u256(arr: Span<u8>) -> u256

u32s_to_u256

Converts an array of 8 u32 values to a u256 value.

Arguments

  • arr - Span of u32 values (must be exactly 8 elements)

Returns

  • u256 - The converted u256 value

Fully qualified path: alexandria_bytes::utils::u32s_to_u256

pub fn u32s_to_u256(arr: Span<u32>) -> u256

u128_array_slice

Returns the slice of an array.

Arguments

  • arr - The array to slice.
  • begin - The index to start the slice at.
  • len - The length of the slice.

Returns

  • Array<u128> - The slice of the array.

Fully qualified path: alexandria_bytes::utils::u128_array_slice

pub fn u128_array_slice(src: @Array<u128>, mut begin: u32, len: u32) -> Array<u128>

u128_split

Split a u128 into two parts, 0, left_size-1 and left_size, end

Arguments

  • value - data of u128
  • value_size - the size of value in bytes
  • left_size - the size of left part in bytes

Returns

  • left - 0, left_size-1 of the origin u128
  • right - left_size, end of the origin u128 which size is (value_size - left_size)

Examples

u128_split(0x01020304, 4, 0) -> (0, 0x01020304)
u128_split(0x01020304, 4, 1) -> (0x01, 0x020304)
u128_split(0x0001020304, 5, 1) -> (0x00, 0x01020304)

Fully qualified path: alexandria_bytes::utils::u128_split

pub fn u128_split(value: u128, value_size: u32, left_size: u32) -> (u128, u128)

read_sub_u128

Read sub value from u128 just like substr in other language

Arguments

  • value - data of u128
  • value_size - the size of data in bytes
  • offset - the offset of sub value
  • size - the size of sub value in bytes

Returns

  • sub_value - the sub value of origin u128

Examples

u128_sub_value(0x000001020304, 6, 1, 3) -> 0x000102

Fully qualified path: alexandria_bytes::utils::read_sub_u128

pub fn read_sub_u128(value: u128, value_size: u32, offset: u32, size: u32) -> u128

u128_join

Join two u128 into one

Arguments

  • left - the left part of u128
  • right - the right part of u128
  • right_size - the size of right part in bytes

Returns

  • value - the joined u128

Examples

u128_join(0x010203, 0xaabb, 2) -> 0x010203aabb
u128_join(0x010203, 0, 2) -> 0x0102030000

Fully qualified path: alexandria_bytes::utils::u128_join

pub fn u128_join(left: u128, right: u128, right_size: u32) -> u128

Impls

Impls

BytesDebugImplementation of Debug trait for Bytes. Formats the Bytes as a hexadecimal string prefixed with “0x”.
BytesDisplayImplementation of Display trait for Bytes. Formats the Bytes as a hexadecimal string prefixed with “0x”.

BytesDebug

Implementation of Debug trait for Bytes. Formats the Bytes as a hexadecimal string prefixed with “0x”.

Fully qualified path: alexandria_bytes::utils::BytesDebug

pub impl BytesDebug of Debug<Bytes>;

Impl functions

fmt

Fully qualified path: alexandria_bytes::utils::BytesDebug::fmt

fn fmt(self: @Bytes, ref f: Formatter) -> Result<(), Error>

BytesDisplay

Implementation of Display trait for Bytes. Formats the Bytes as a hexadecimal string prefixed with “0x”.

Fully qualified path: alexandria_bytes::utils::BytesDisplay

pub impl BytesDisplay of Display<Bytes>;

Impl functions

fmt

Fully qualified path: alexandria_bytes::utils::BytesDisplay::fmt

fn fmt(self: @Bytes, ref f: Formatter) -> Result<(), Error>