byte_array
BytesArray. ByteArray
is designed to handle large sequences of bytes with operations like appending, concatenation, and accessing individual bytes. It uses a structure that combines an Array
of bytes31
for full words and a felt252
for handling partial words, optimizing for both space and performance. # Examples There are multiple ways to create a new ByteArray
: - From a string literal:
let s = "Hello";
Using the format!
macro:
let max_tps:u16 = 850;
let s = format!("Starknet's max TPS is: {}", max_tps);
You can append bytes to an existing ByteArray
with ByteArrayTrait::append_byte
:
let mut ba: ByteArray = "";
ba.append_byte(0x41); // Appending a single byte 'A'
You can create a new ByteArray
from an existing one by concatenating with +
:
let s = "Hello";
let message = s + " world!";
Indexing operations are available on the ByteArray
type as well:
let mut ba: ByteArray = "ABC";
let first_bytes = ba[0]
assert!(first_byte == 0x41);
Fully qualified path: core::byte_array