Skip to content

Instantly share code, notes, and snippets.

@hihiben
Created August 16, 2022 02:40
Show Gist options
  • Save hihiben/96981d4e432a3afa7cc342b89188d8b0 to your computer and use it in GitHub Desktop.
Save hihiben/96981d4e432a3afa7cc342b89188d8b0 to your computer and use it in GitHub Desktop.
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.16+commit.07a7930e.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract Try {
function createBytes(uint256 n) public pure returns (bytes memory data) {
uint256[] memory ret = new uint256[](n);
for (uint256 i = 0; i < n; i++) {
ret[i] = i;
}
data = abi.encode(ret);
}
function decodeBytes(bytes memory data) public pure returns (uint256[] memory ret) {
return abi.decode(data, (uint256[]));
}
function decodeBytes(uint256 n) public pure returns (uint256[] memory ret) {
bytes memory data = createBytes(n);
return decodeBytes(data);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment