Decode the pending word in a Cairo ByteArray
Cairo serializes long byte strings in complete 31-byte words plus a trailing partial word. Reading the first field as the total byte length misaligns every later argument.
Walk two boundary cases
For abc there are no complete words. The first felt is therefore zero, followed by the pending word and its length three. For exactly 31 bytes there is one complete word and an empty pending part.
ByteArray("abc") → [0, 0x616263, 3]
ByteArray(31 bytes) → [1, full_word, 0, 0]
Reconstruct each full word as exactly 31 bytes. Decode the pending word using pending_word_len bytes, preserving leading zeros within that length. The total byte count is 31 times the number of full words plus the pending length.
Decode text only after reconstructing bytes
A multibyte UTF-8 character may span the boundary between two serialized words. Assemble the bytes before UTF-8 validation. For arbitrary bytes keep a binary representation instead of replacing invalid sequences and losing round-trip fidelity. starknet.io The Cairo Programming Language