Expand description
Bytes-like (Bytes, String) implementation for the storage traits.
§Storage Layout
Bytes-like types use Solidity-compatible: Short strings (≤31 bytes) are stored inline in a single slot:
- Bytes 0..len: UTF-8 string data (left-aligned)
- Byte 31 (LSB): length * 2 (bit 0 = 0 indicates short string)
Long strings (≥32 bytes) use keccak256-based storage:
- Base slot: stores
length * 2 + 1(bit 0 = 1 indicates long string) - Data slots: stored at
keccak256(main_slot) + ifor each 32-byte chunk
Functions§
- calc_
chunks 🔒 - Compute the number of 32-byte chunks needed to store a byte string.
- calc_
data_ 🔒slot - Compute the storage slot where long string data begins.
- calc_
string_ 🔒length - Extract the string length from a storage slot value.
- delete_
bytes_ 🔒like - Generic delete implementation for byte-like types (String, Bytes) using Solidity’s encoding.
- encode_
long_ 🔒string_ length - Encode the length metadata for a long string (≥32 bytes).
- encode_
short_ 🔒string - Encode a short string (≤31 bytes) into a U256 for inline storage.
- is_
long_ 🔒string - Check if a storage slot value represents a long string.
- load_
bytes_ 🔒like - Generic load implementation for string-like types (String, Bytes) using Solidity’s encoding.
- store_
bytes_ 🔒like - Generic store implementation for byte-like types (String, Bytes) using Solidity’s encoding.