LibBytes
Last updated
Last updated
These utility functions provide convenient operations for manipulating byte arrays in Solidity.
This function is used to convert a portion of a byte array into an address
. It takes in the byte array (self
) and a starting index (start
). It verifies that the byte array has enough bytes to read an address (20 bytes) starting from the specified index. Then, it uses assembly code to load the address from the specified location in memory and returns it.
Input:
Field | Type | Description |
---|---|---|
Output:
Field | Type | Description |
---|---|---|
This function is used to extract a slice of bytes from a byte array. It takes in the byte array (self
), a starting index (start
), and a length (length
). It checks that the specified slice is within the bounds of the byte array. Then, it creates a new byte array (tempBytes
) with a length equal to the specified slice length. It uses assembly code to copy the slice from the original byte array to the new byte array. Finally, it updates the length of the new byte array and returns it.
Input:
Field | Type | Description |
---|---|---|
Output:
Field | Type | Description |
---|---|---|
This function is used to concatenate two byte arrays. It takes in two byte arrays (self
and postBytes
). It creates a new byte array (tempBytes
) with a length equal to the combined lengths of the two input byte arrays. It uses assembly code to copy the contents of the two byte arrays into the new byte array. Finally, it updates the length of the new byte array and returns it.
Input:
Output:
Field | Type | Description |
---|---|---|
Field | Type | Description |
---|---|---|
The bytes that contains the address.
The starting position to retrieve the address from the bytes.
The retrieved address from the bytes.
The string of bytes that needs to be sliced
The starting position to begin slicing
The length of the byte
The sliced byte
The bytes that needs to be concatenated.
The bytes that needs to be concatenated.
The concatenated bytes