Skip to content

Commit 0061b62

Browse files
authored
v0.0.8 - Additional uint typecasting methods (#28)
* 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
1 parent 14ca2bd commit 0061b62

6 files changed

Lines changed: 151 additions & 333 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ $ npm install solidity-bytes-utils
6161
**Importing it in your Solidity contract**
6262

6363
```
64-
import "solidity-bytes-utils/BytesLib.sol";
64+
import "solidity-bytes-utils/contracts/BytesLib.sol";
6565
```
6666

6767
## Contributing

contracts/BytesLib.sol

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,39 @@ library BytesLib {
334334
return tempUint;
335335
}
336336

337+
function toUint64(bytes memory _bytes, uint _start) internal pure returns (uint64) {
338+
require(_bytes.length >= (_start + 8));
339+
uint64 tempUint;
340+
341+
assembly {
342+
tempUint := mload(add(add(_bytes, 0x8), _start))
343+
}
344+
345+
return tempUint;
346+
}
347+
348+
function toUint96(bytes memory _bytes, uint _start) internal pure returns (uint96) {
349+
require(_bytes.length >= (_start + 12));
350+
uint96 tempUint;
351+
352+
assembly {
353+
tempUint := mload(add(add(_bytes, 0xc), _start))
354+
}
355+
356+
return tempUint;
357+
}
358+
359+
function toUint128(bytes memory _bytes, uint _start) internal pure returns (uint128) {
360+
require(_bytes.length >= (_start + 16));
361+
uint128 tempUint;
362+
363+
assembly {
364+
tempUint := mload(add(add(_bytes, 0x10), _start))
365+
}
366+
367+
return tempUint;
368+
}
369+
337370
function toUint(bytes memory _bytes, uint _start) internal pure returns (uint256) {
338371
require(_bytes.length >= (_start + 32));
339372
uint256 tempUint;

ethpm.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"package_name": "bytes",
3-
"version": "0.0.7",
3+
"version": "0.0.8",
44
"description": "Solidity bytes tightly packed arrays utility library.",
55
"authors": [
66
"Gonçalo Sá <goncalo.sa@consensys.net>"

0 commit comments

Comments
 (0)