Skip to content

Commit

Permalink
v0.0.8 - Additional uint typecasting methods (#28)
Browse files Browse the repository at this point in the history
* Implement toUintXX for 64, 96 and 128 bits (#25)

* include toUintXX for 64, 96 and 128 bits

* Update tests to follow same style as the others

* Fix README with correct example of import from NPM

* Update dependencies

* Bump version to 0.0.8

Fixes #27
  • Loading branch information
GNSPS committed Jun 26, 2019
1 parent 14ca2bd commit 0061b62
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 333 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -61,7 +61,7 @@ $ npm install solidity-bytes-utils
**Importing it in your Solidity contract**

```
import "solidity-bytes-utils/BytesLib.sol";
import "solidity-bytes-utils/contracts/BytesLib.sol";
```

## Contributing
Expand Down
33 changes: 33 additions & 0 deletions contracts/BytesLib.sol
Expand Up @@ -334,6 +334,39 @@ library BytesLib {
return tempUint;
}

function toUint64(bytes memory _bytes, uint _start) internal pure returns (uint64) {
require(_bytes.length >= (_start + 8));
uint64 tempUint;

assembly {
tempUint := mload(add(add(_bytes, 0x8), _start))
}

return tempUint;
}

function toUint96(bytes memory _bytes, uint _start) internal pure returns (uint96) {
require(_bytes.length >= (_start + 12));
uint96 tempUint;

assembly {
tempUint := mload(add(add(_bytes, 0xc), _start))
}

return tempUint;
}

function toUint128(bytes memory _bytes, uint _start) internal pure returns (uint128) {
require(_bytes.length >= (_start + 16));
uint128 tempUint;

assembly {
tempUint := mload(add(add(_bytes, 0x10), _start))
}

return tempUint;
}

function toUint(bytes memory _bytes, uint _start) internal pure returns (uint256) {
require(_bytes.length >= (_start + 32));
uint256 tempUint;
Expand Down
2 changes: 1 addition & 1 deletion ethpm.json
@@ -1,6 +1,6 @@
{
"package_name": "bytes",
"version": "0.0.7",
"version": "0.0.8",
"description": "Solidity bytes tightly packed arrays utility library.",
"authors": [
"Gonçalo Sá <goncalo.sa@consensys.net>"
Expand Down

0 comments on commit 0061b62

Please sign in to comment.