Keyboard shortcuts

Press or to navigate between chapters

Press ? to show this help

Press Esc to hide this help

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