Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add bytes12 to Bytes.sol #2402

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/pages/store/reference/misc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,27 @@ function slice8(bytes memory data, uint256 start) internal pure returns (bytes8
| -------- | -------- | ------------------------------------------------------------------------- |
| `output` | `bytes8` | The extracted bytes8 value from the specified position in the bytes blob. |

#### slice12

_Extracts a 12-byte sequence from a bytes blob starting at a specific position._

```solidity
function slice12(bytes memory data, uint256 start) internal pure returns (bytes12 output);
```

**Parameters**

| Name | Type | Description |
| ------- | --------- | ---------------------------------------------------------------- |
| `data` | `bytes` | The bytes blob from which a 12-byte sequence is to be extracted. |
| `start` | `uint256` | The starting position within the bytes blob for extraction. |

**Returns**

| Name | Type | Description |
| -------- | --------- | -------------------------------------------------------------------------- |
| `output` | `bytes12` | The extracted bytes12 value from the specified position in the bytes blob. |

#### slice16

_Extracts a 16-byte sequence from a bytes blob starting at a specific position._
Expand Down
12 changes: 12 additions & 0 deletions packages/store/src/Bytes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ library Bytes {
}
}

/**
* @dev Extracts a 12-byte sequence from a bytes blob starting at a specific position.
* @param data The bytes blob from which a 12-byte sequence is to be extracted.
* @param start The starting position within the bytes blob for extraction.
* @return output The extracted bytes12 value from the specified position in the bytes blob.
*/
function slice12(bytes memory data, uint256 start) internal pure returns (bytes12 output) {
assembly {
output := mload(add(add(data, 0x20), start))
}
}

/**
* @dev Extracts a 20-byte sequence from a bytes blob starting at a specific position.
* @param data The bytes blob from which a 20-byte sequence is to be extracted.
Expand Down
Loading