From 80bad46d6b723e7d740cb124fe034d108324a893 Mon Sep 17 00:00:00 2001 From: dk1a Date: Fri, 21 Jul 2023 18:44:43 +0300 Subject: [PATCH] add abiEncodeTightlyPacked, partially refactor tightcoder --- .../src/codegen/render-solidity/common.ts | 12 + packages/store/gas-report.json | 16 +- packages/store/src/Memory.sol | 19 + packages/store/src/tightcoder/EncodeArray.sol | 1094 ++++- packages/store/src/tightcoder/TightCoder.sol | 27 +- .../test/tightcoder/TightCoderAuto.t.sol | 3521 +++++++++++++++-- .../tightcoder/abiEncodeTightlyPacked.ts | 58 + .../codegen/tightcoder/renderDecodeSlice.ts | 10 +- .../codegen/tightcoder/renderEncodeArray.ts | 10 +- .../ts/codegen/tightcoder/renderFunctions.ts | 40 +- .../tightcoder/renderTightCoderAutoTest.ts | 38 + packages/world/gas-report.json | 6 +- pnpm-lock.yaml | 54 +- 13 files changed, 4408 insertions(+), 497 deletions(-) create mode 100644 packages/store/ts/codegen/tightcoder/abiEncodeTightlyPacked.ts diff --git a/packages/common/src/codegen/render-solidity/common.ts b/packages/common/src/codegen/render-solidity/common.ts index d8ea6dc0ef..54399134f2 100644 --- a/packages/common/src/codegen/render-solidity/common.ts +++ b/packages/common/src/codegen/render-solidity/common.ts @@ -180,6 +180,18 @@ export function renderValueTypeToBytes32(name: string, { typeUnwrap, internalTyp } } +export function isLeftAligned(field: Pick): boolean { + return field.internalTypeId.match(/^bytes\d{1,2}$/) !== null; +} + +export function shiftLeftBits(field: Pick): number { + if (isLeftAligned(field)) { + return 0; + } else { + return 256 - field.staticByteLength * 8; + } +} + function internalRenderList( lineTerminator: string, list: T[], diff --git a/packages/store/gas-report.json b/packages/store/gas-report.json index 66c0423697..5fee1ad0c8 100644 --- a/packages/store/gas-report.json +++ b/packages/store/gas-report.json @@ -75,7 +75,7 @@ "file": "test/Gas.t.sol", "test": "testCompareAbiEncodeVsCustom", "name": "custom encode", - "gasUsed": 1812 + "gasUsed": 1379 }, { "file": "test/Gas.t.sol", @@ -117,7 +117,7 @@ "file": "test/Mixed.t.sol", "test": "testSetAndGet", "name": "set record in Mixed", - "gasUsed": 111108 + "gasUsed": 110678 }, { "file": "test/Mixed.t.sol", @@ -645,7 +645,7 @@ "file": "test/tables/Callbacks.t.sol", "test": "testSetAndGet", "name": "set field in Callbacks", - "gasUsed": 62243 + "gasUsed": 61982 }, { "file": "test/tables/Callbacks.t.sol", @@ -663,7 +663,7 @@ "file": "test/tables/Hooks.t.sol", "test": "testSetAndGet", "name": "set field in Hooks", - "gasUsed": 64400 + "gasUsed": 63973 }, { "file": "test/tables/Hooks.t.sol", @@ -693,19 +693,19 @@ "file": "test/tightcoder/EncodeArray.t.sol", "test": "testEncodeUint16Array", "name": "encode packed uint16[]", - "gasUsed": 1143 + "gasUsed": 710 }, { "file": "test/tightcoder/EncodeArray.t.sol", "test": "testEncodeUint32Array", "name": "encode packed uint32[]", - "gasUsed": 1049 + "gasUsed": 619 }, { "file": "test/tightcoder/EncodeArray.t.sol", "test": "testEncodeUint8Array", "name": "encode packed uint8[]", - "gasUsed": 1038 + "gasUsed": 608 }, { "file": "test/tightcoder/TightCoder.t.sol", @@ -717,7 +717,7 @@ "file": "test/tightcoder/TightCoder.t.sol", "test": "testToAndFromBytes24Array", "name": "encode packed bytes24[]", - "gasUsed": 880 + "gasUsed": 608 }, { "file": "test/tightcoder/TightCoder.t.sol", diff --git a/packages/store/src/Memory.sol b/packages/store/src/Memory.sol index 1856cc18a9..c98d576504 100644 --- a/packages/store/src/Memory.sol +++ b/packages/store/src/Memory.sol @@ -44,4 +44,23 @@ library Memory { ) } } + + /** + * mstore n bytes (left-aligned) of given data + */ + function mstoreN(bytes32 data, uint256 toPointer, uint256 n) internal pure { + uint256 mask = leftMask(n); + /// @solidity memory-safe-assembly + assembly { + mstore( + toPointer, + or( + // store the left part + and(data, mask), + // preserve the right part + and(mload(toPointer), not(mask)) + ) + ) + } + } } diff --git a/packages/store/src/tightcoder/EncodeArray.sol b/packages/store/src/tightcoder/EncodeArray.sol index 25f026f3e5..4a21e78654 100644 --- a/packages/store/src/tightcoder/EncodeArray.sol +++ b/packages/store/src/tightcoder/EncodeArray.sol @@ -11,260 +11,548 @@ library EncodeArray { * uint8 - uint256 * ************************************************************************/ + function encodeToLocation(uint8[] memory _input, uint256 _toPointer) internal pure { + bytes32[] memory _genericArray; + assembly { + _genericArray := _input + } + TightCoder.encodeToLocation(_genericArray, _toPointer, 1, 248); + } + function encode(uint8[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 1); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint16[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 1, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 2, 240); } function encode(uint16[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 2); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint24[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 2, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 3, 232); } function encode(uint24[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 3); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint32[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 3, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 4, 224); } function encode(uint32[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 4); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint40[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 4, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 5, 216); } function encode(uint40[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 5); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint48[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 5, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 6, 208); } function encode(uint48[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 6); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint56[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 6, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 7, 200); } function encode(uint56[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 7); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint64[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 7, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 8, 192); } function encode(uint64[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 8); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint72[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 8, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 9, 184); } function encode(uint72[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 9); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint80[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 9, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 10, 176); } function encode(uint80[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 10); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint88[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 10, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 11, 168); } function encode(uint88[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 11); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint96[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 11, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 12, 160); } function encode(uint96[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 12); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint104[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 12, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 13, 152); } function encode(uint104[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 13); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint112[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 13, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 14, 144); } function encode(uint112[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 14); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint120[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 14, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 15, 136); } function encode(uint120[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 15); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint128[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 15, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 16, 128); } function encode(uint128[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 16); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint136[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 16, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 17, 120); } function encode(uint136[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 17); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint144[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 17, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 18, 112); } function encode(uint144[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 18); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint152[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 18, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 19, 104); } function encode(uint152[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 19); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint160[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 19, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 20, 96); } function encode(uint160[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 20); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint168[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 20, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 21, 88); } function encode(uint168[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 21); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint176[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 21, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 22, 80); } function encode(uint176[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 22); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint184[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 22, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 23, 72); } function encode(uint184[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 23); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint192[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 23, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 24, 64); } function encode(uint192[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 24); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint200[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 24, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 25, 56); } function encode(uint200[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 25); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint208[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 25, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 26, 48); } function encode(uint208[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 26); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint216[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 26, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 27, 40); } function encode(uint216[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 27); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint224[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 27, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 28, 32); } function encode(uint224[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 28); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint232[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 28, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 29, 24); } function encode(uint232[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 29); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint240[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 29, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 30, 16); } function encode(uint240[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 30); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint248[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 30, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 31, 8); } function encode(uint248[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 31); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(uint256[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 31, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 32, 0); } function encode(uint256[] memory _input) internal pure returns (bytes memory _output) { - bytes32[] memory _genericArray; + _output = new bytes(_input.length * 32); + uint256 _toPointer; assembly { - _genericArray := _input + _toPointer := add(_output, 0x20) } - return TightCoder.encode(_genericArray, 32, false); + encodeToLocation(_input, _toPointer); } /************************************************************************ @@ -272,260 +560,548 @@ library EncodeArray { * int8 - int256 * ************************************************************************/ + function encodeToLocation(int8[] memory _input, uint256 _toPointer) internal pure { + bytes32[] memory _genericArray; + assembly { + _genericArray := _input + } + TightCoder.encodeToLocation(_genericArray, _toPointer, 1, 248); + } + function encode(int8[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 1); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int16[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 1, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 2, 240); } function encode(int16[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 2); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int24[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 2, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 3, 232); } function encode(int24[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 3); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int32[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 3, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 4, 224); } function encode(int32[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 4); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int40[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 4, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 5, 216); } function encode(int40[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 5); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int48[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 5, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 6, 208); } function encode(int48[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 6); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int56[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 6, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 7, 200); } function encode(int56[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 7); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int64[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 7, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 8, 192); } function encode(int64[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 8); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int72[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 8, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 9, 184); } function encode(int72[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 9); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int80[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 9, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 10, 176); } function encode(int80[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 10); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int88[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 10, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 11, 168); } function encode(int88[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 11); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int96[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 11, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 12, 160); } function encode(int96[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 12); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int104[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 12, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 13, 152); } function encode(int104[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 13); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int112[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 13, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 14, 144); } function encode(int112[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 14); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int120[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 14, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 15, 136); } function encode(int120[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 15); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int128[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 15, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 16, 128); } function encode(int128[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 16); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int136[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 16, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 17, 120); } function encode(int136[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 17); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int144[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 17, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 18, 112); } function encode(int144[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 18); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int152[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 18, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 19, 104); } function encode(int152[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 19); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int160[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 19, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 20, 96); } function encode(int160[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 20); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int168[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 20, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 21, 88); } function encode(int168[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 21); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int176[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 21, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 22, 80); } function encode(int176[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 22); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int184[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 22, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 23, 72); } function encode(int184[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 23); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int192[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 23, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 24, 64); } function encode(int192[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 24); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int200[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 24, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 25, 56); } function encode(int200[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 25); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int208[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 25, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 26, 48); } function encode(int208[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 26); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int216[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 26, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 27, 40); } function encode(int216[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 27); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int224[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 27, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 28, 32); } function encode(int224[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 28); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int232[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 28, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 29, 24); } function encode(int232[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 29); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int240[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 29, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 30, 16); } function encode(int240[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 30); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int248[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 30, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 31, 8); } function encode(int248[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 31); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(int256[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 31, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 32, 0); } function encode(int256[] memory _input) internal pure returns (bytes memory _output) { - bytes32[] memory _genericArray; + _output = new bytes(_input.length * 32); + uint256 _toPointer; assembly { - _genericArray := _input + _toPointer := add(_output, 0x20) } - return TightCoder.encode(_genericArray, 32, false); + encodeToLocation(_input, _toPointer); } /************************************************************************ @@ -533,260 +1109,548 @@ library EncodeArray { * bytes1 - bytes32 * ************************************************************************/ + function encodeToLocation(bytes1[] memory _input, uint256 _toPointer) internal pure { + bytes32[] memory _genericArray; + assembly { + _genericArray := _input + } + TightCoder.encodeToLocation(_genericArray, _toPointer, 1, 0); + } + function encode(bytes1[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 1); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes2[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 1, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 2, 0); } function encode(bytes2[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 2); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes3[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 2, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 3, 0); } function encode(bytes3[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 3); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes4[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 3, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 4, 0); } function encode(bytes4[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 4); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes5[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 4, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 5, 0); } function encode(bytes5[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 5); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes6[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 5, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 6, 0); } function encode(bytes6[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 6); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes7[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 6, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 7, 0); } function encode(bytes7[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 7); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes8[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 7, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 8, 0); } function encode(bytes8[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 8); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes9[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 8, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 9, 0); } function encode(bytes9[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 9); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes10[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 9, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 10, 0); } function encode(bytes10[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 10); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes11[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 10, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 11, 0); } function encode(bytes11[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 11); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes12[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 11, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 12, 0); } function encode(bytes12[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 12); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes13[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 12, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 13, 0); } function encode(bytes13[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 13); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes14[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 13, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 14, 0); } function encode(bytes14[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 14); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes15[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 14, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 15, 0); } function encode(bytes15[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 15); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes16[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 15, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 16, 0); } function encode(bytes16[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 16); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes17[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 16, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 17, 0); } function encode(bytes17[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 17); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes18[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 17, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 18, 0); } function encode(bytes18[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 18); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes19[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 18, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 19, 0); } function encode(bytes19[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 19); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes20[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 19, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 20, 0); } function encode(bytes20[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 20); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes21[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 20, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 21, 0); } function encode(bytes21[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 21); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes22[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 21, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 22, 0); } function encode(bytes22[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 22); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes23[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 22, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 23, 0); } function encode(bytes23[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 23); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes24[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 23, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 24, 0); } function encode(bytes24[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 24); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes25[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 24, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 25, 0); } function encode(bytes25[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 25); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes26[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 25, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 26, 0); } function encode(bytes26[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 26); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes27[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 26, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 27, 0); } function encode(bytes27[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 27); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes28[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 27, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 28, 0); } function encode(bytes28[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 28); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes29[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 28, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 29, 0); } function encode(bytes29[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 29); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes30[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 29, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 30, 0); } function encode(bytes30[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 30); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes31[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 30, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 31, 0); } function encode(bytes31[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 31); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bytes32[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 31, true); + TightCoder.encodeToLocation(_genericArray, _toPointer, 32, 0); } function encode(bytes32[] memory _input) internal pure returns (bytes memory _output) { - bytes32[] memory _genericArray; + _output = new bytes(_input.length * 32); + uint256 _toPointer; assembly { - _genericArray := _input + _toPointer := add(_output, 0x20) } - return TightCoder.encode(_genericArray, 32, true); + encodeToLocation(_input, _toPointer); } /************************************************************************ @@ -796,19 +1660,37 @@ library EncodeArray { ************************************************************************/ // Note: internally address is right-aligned, like uint160 - function encode(address[] memory _input) internal pure returns (bytes memory _output) { + function encodeToLocation(address[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 20, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 20, 96); } - function encode(bool[] memory _input) internal pure returns (bytes memory _output) { + function encode(address[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 20); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); + } + + function encodeToLocation(bool[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, 1, false); + TightCoder.encodeToLocation(_genericArray, _toPointer, 1, 248); + } + + function encode(bool[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * 1); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); } } diff --git a/packages/store/src/tightcoder/TightCoder.sol b/packages/store/src/tightcoder/TightCoder.sol index 200f9e4290..de4142c9f4 100644 --- a/packages/store/src/tightcoder/TightCoder.sol +++ b/packages/store/src/tightcoder/TightCoder.sol @@ -12,36 +12,25 @@ library TightCoder { * TODO this function is currently not used externally and will be changed in the future * (see https://github.com/latticexyz/mud/issues/444) */ - function _encodeToLocation( + function encodeToLocation( bytes32[] memory array, - Slice packedSlice, + uint256 toPointer, uint256 elementSize, - bool leftAligned - ) private pure { + uint256 shiftLeftBits + ) internal pure { uint256 arrayLength = array.length; - uint256 packedPointer = packedSlice.pointer(); - uint256 shiftLeft = leftAligned ? 0 : 256 - elementSize * 8; - - // TODO temporary check to catch bugs, either remove it or use a custom error - // (see https://github.com/latticexyz/mud/issues/444) - uint256 packedLength = arrayLength * elementSize; - if (packedLength > packedSlice.length()) { - revert("packFromArray: insufficient allocated packedSlice length"); - } - /// @solidity memory-safe-assembly assembly { for { let i := 0 let arrayCursor := add(array, 0x20) // skip array length - let packedCursor := packedPointer } lt(i, arrayLength) { // Loop until we reach the end of the array i := add(i, 1) arrayCursor := add(arrayCursor, 0x20) // increment array pointer by one word - packedCursor := add(packedCursor, elementSize) // increment packed pointer by one element size + toPointer := add(toPointer, elementSize) // increment packed pointer by one element size } { - mstore(packedCursor, shl(shiftLeft, mload(arrayCursor))) // pack one array element + mstore(toPointer, shl(shiftLeftBits, mload(arrayCursor))) // pack one array element } } } @@ -50,7 +39,7 @@ library TightCoder { * @dev Copies the array to a new bytes array, * tightly packing it using the given size per element (in bytes) */ - function encode( + /*function encode( bytes32[] memory array, uint256 elementSize, bool leftAligned @@ -58,7 +47,7 @@ library TightCoder { uint256 packedLength = array.length * elementSize; data = new bytes(packedLength); _encodeToLocation(array, SliceLib.fromBytes(data), elementSize, leftAligned); - } + }*/ /** * @dev Unpacks the slice to a new memory location diff --git a/packages/store/test/tightcoder/TightCoderAuto.t.sol b/packages/store/test/tightcoder/TightCoderAuto.t.sol index 496bb6f6b7..060f0dcefc 100644 --- a/packages/store/test/tightcoder/TightCoderAuto.t.sol +++ b/packages/store/test/tightcoder/TightCoderAuto.t.sol @@ -6,6 +6,7 @@ pragma solidity >=0.8.0; import "forge-std/Test.sol"; import { Bytes } from "../../src/Bytes.sol"; import { EncodeArray } from "../../src/tightcoder/EncodeArray.sol"; +import { Memory } from "../../src/Memory.sol"; import { SliceLib } from "../../src/Slice.sol"; contract TightCoderAutoTest is Test { @@ -14,13 +15,25 @@ contract TightCoderAutoTest is Test { * uint8 - uint256 * ************************************************************************/ + function encode_uint8(uint8[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 1; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 1; + + return _result; + } + function testEncodeDecodeArray_uint8(uint8 val0, uint8 val1, uint8 val2) public { uint8[] memory input = new uint8[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint8(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); uint8[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint8(); @@ -30,8 +43,9 @@ contract TightCoderAutoTest is Test { assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint16(uint16 val0, uint16 val1, uint16 val2) public { - uint16[] memory input = new uint16[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint8(uint8 val0, uint8 val1, uint8 val2) public { + uint8[] memory input = new uint8[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -39,31 +53,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint16[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint16(); + uint8[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint8(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint24(uint24 val0, uint24 val1, uint24 val2) public { - uint24[] memory input = new uint24[](3); + function encode_uint16(uint16[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 2; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 2; + + return _result; + } + + function testEncodeDecodeArray_uint16(uint16 val0, uint16 val1, uint16 val2) public { + uint16[] memory input = new uint16[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint16(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint24[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint24(); + uint16[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint16(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint32(uint32 val0, uint32 val1, uint32 val2) public { - uint32[] memory input = new uint32[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint16(uint16 val0, uint16 val1, uint16 val2) public { + uint16[] memory input = new uint16[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -71,31 +98,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint32[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint32(); + uint16[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint16(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint40(uint40 val0, uint40 val1, uint40 val2) public { - uint40[] memory input = new uint40[](3); + function encode_uint24(uint24[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 3; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 3; + + return _result; + } + + function testEncodeDecodeArray_uint24(uint24 val0, uint24 val1, uint24 val2) public { + uint24[] memory input = new uint24[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint24(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint40[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint40(); + uint24[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint24(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint48(uint48 val0, uint48 val1, uint48 val2) public { - uint48[] memory input = new uint48[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint24(uint24 val0, uint24 val1, uint24 val2) public { + uint24[] memory input = new uint24[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -103,31 +143,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint48[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint48(); + uint24[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint24(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint56(uint56 val0, uint56 val1, uint56 val2) public { - uint56[] memory input = new uint56[](3); + function encode_uint32(uint32[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 4; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 4; + + return _result; + } + + function testEncodeDecodeArray_uint32(uint32 val0, uint32 val1, uint32 val2) public { + uint32[] memory input = new uint32[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint32(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint56[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint56(); + uint32[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint32(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint64(uint64 val0, uint64 val1, uint64 val2) public { - uint64[] memory input = new uint64[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint32(uint32 val0, uint32 val1, uint32 val2) public { + uint32[] memory input = new uint32[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -135,31 +188,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint64[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint64(); + uint32[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint32(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint72(uint72 val0, uint72 val1, uint72 val2) public { - uint72[] memory input = new uint72[](3); + function encode_uint40(uint40[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 5; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 5; + + return _result; + } + + function testEncodeDecodeArray_uint40(uint40 val0, uint40 val1, uint40 val2) public { + uint40[] memory input = new uint40[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint40(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint72[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint72(); + uint40[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint40(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint80(uint80 val0, uint80 val1, uint80 val2) public { - uint80[] memory input = new uint80[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint40(uint40 val0, uint40 val1, uint40 val2) public { + uint40[] memory input = new uint40[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -167,31 +233,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint80[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint80(); + uint40[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint40(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint88(uint88 val0, uint88 val1, uint88 val2) public { - uint88[] memory input = new uint88[](3); + function encode_uint48(uint48[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 6; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 6; + + return _result; + } + + function testEncodeDecodeArray_uint48(uint48 val0, uint48 val1, uint48 val2) public { + uint48[] memory input = new uint48[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint48(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint88[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint88(); + uint48[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint48(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint96(uint96 val0, uint96 val1, uint96 val2) public { - uint96[] memory input = new uint96[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint48(uint48 val0, uint48 val1, uint48 val2) public { + uint48[] memory input = new uint48[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -199,31 +278,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint96[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint96(); + uint48[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint48(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint104(uint104 val0, uint104 val1, uint104 val2) public { - uint104[] memory input = new uint104[](3); + function encode_uint56(uint56[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 7; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 7; + + return _result; + } + + function testEncodeDecodeArray_uint56(uint56 val0, uint56 val1, uint56 val2) public { + uint56[] memory input = new uint56[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint56(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint104[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint104(); + uint56[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint56(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint112(uint112 val0, uint112 val1, uint112 val2) public { - uint112[] memory input = new uint112[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint56(uint56 val0, uint56 val1, uint56 val2) public { + uint56[] memory input = new uint56[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -231,31 +323,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint112[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint112(); + uint56[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint56(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint120(uint120 val0, uint120 val1, uint120 val2) public { - uint120[] memory input = new uint120[](3); + function encode_uint64(uint64[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 8; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 8; + + return _result; + } + + function testEncodeDecodeArray_uint64(uint64 val0, uint64 val1, uint64 val2) public { + uint64[] memory input = new uint64[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint64(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint120[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint120(); + uint64[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint64(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint128(uint128 val0, uint128 val1, uint128 val2) public { - uint128[] memory input = new uint128[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint64(uint64 val0, uint64 val1, uint64 val2) public { + uint64[] memory input = new uint64[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -263,31 +368,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint128[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint128(); + uint64[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint64(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint136(uint136 val0, uint136 val1, uint136 val2) public { - uint136[] memory input = new uint136[](3); + function encode_uint72(uint72[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 9; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 9; + + return _result; + } + + function testEncodeDecodeArray_uint72(uint72 val0, uint72 val1, uint72 val2) public { + uint72[] memory input = new uint72[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint72(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint136[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint136(); + uint72[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint72(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint144(uint144 val0, uint144 val1, uint144 val2) public { - uint144[] memory input = new uint144[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint72(uint72 val0, uint72 val1, uint72 val2) public { + uint72[] memory input = new uint72[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -295,31 +413,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint144[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint144(); + uint72[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint72(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint152(uint152 val0, uint152 val1, uint152 val2) public { - uint152[] memory input = new uint152[](3); + function encode_uint80(uint80[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 10; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 10; + + return _result; + } + + function testEncodeDecodeArray_uint80(uint80 val0, uint80 val1, uint80 val2) public { + uint80[] memory input = new uint80[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint80(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint152[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint152(); + uint80[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint80(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint160(uint160 val0, uint160 val1, uint160 val2) public { - uint160[] memory input = new uint160[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint80(uint80 val0, uint80 val1, uint80 val2) public { + uint80[] memory input = new uint80[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -327,31 +458,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint160[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint160(); + uint80[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint80(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint168(uint168 val0, uint168 val1, uint168 val2) public { - uint168[] memory input = new uint168[](3); + function encode_uint88(uint88[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 11; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 11; + + return _result; + } + + function testEncodeDecodeArray_uint88(uint88 val0, uint88 val1, uint88 val2) public { + uint88[] memory input = new uint88[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint88(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint168[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint168(); + uint88[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint88(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint176(uint176 val0, uint176 val1, uint176 val2) public { - uint176[] memory input = new uint176[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint88(uint88 val0, uint88 val1, uint88 val2) public { + uint88[] memory input = new uint88[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -359,31 +503,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint176[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint176(); + uint88[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint88(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint184(uint184 val0, uint184 val1, uint184 val2) public { - uint184[] memory input = new uint184[](3); + function encode_uint96(uint96[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 12; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 12; + + return _result; + } + + function testEncodeDecodeArray_uint96(uint96 val0, uint96 val1, uint96 val2) public { + uint96[] memory input = new uint96[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint96(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint184[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint184(); + uint96[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint96(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint192(uint192 val0, uint192 val1, uint192 val2) public { - uint192[] memory input = new uint192[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint96(uint96 val0, uint96 val1, uint96 val2) public { + uint96[] memory input = new uint96[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -391,31 +548,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint192[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint192(); + uint96[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint96(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint200(uint200 val0, uint200 val1, uint200 val2) public { - uint200[] memory input = new uint200[](3); + function encode_uint104(uint104[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 13; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 13; + + return _result; + } + + function testEncodeDecodeArray_uint104(uint104 val0, uint104 val1, uint104 val2) public { + uint104[] memory input = new uint104[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint104(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint200[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint200(); + uint104[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint104(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint208(uint208 val0, uint208 val1, uint208 val2) public { - uint208[] memory input = new uint208[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint104(uint104 val0, uint104 val1, uint104 val2) public { + uint104[] memory input = new uint104[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -423,31 +593,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint208[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint208(); + uint104[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint104(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint216(uint216 val0, uint216 val1, uint216 val2) public { - uint216[] memory input = new uint216[](3); + function encode_uint112(uint112[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 14; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 14; + + return _result; + } + + function testEncodeDecodeArray_uint112(uint112 val0, uint112 val1, uint112 val2) public { + uint112[] memory input = new uint112[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint112(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint216[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint216(); + uint112[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint112(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint224(uint224 val0, uint224 val1, uint224 val2) public { - uint224[] memory input = new uint224[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint112(uint112 val0, uint112 val1, uint112 val2) public { + uint112[] memory input = new uint112[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -455,31 +638,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint224[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint224(); + uint112[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint112(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint232(uint232 val0, uint232 val1, uint232 val2) public { - uint232[] memory input = new uint232[](3); + function encode_uint120(uint120[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 15; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 15; + + return _result; + } + + function testEncodeDecodeArray_uint120(uint120 val0, uint120 val1, uint120 val2) public { + uint120[] memory input = new uint120[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint120(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint232[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint232(); + uint120[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint120(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint240(uint240 val0, uint240 val1, uint240 val2) public { - uint240[] memory input = new uint240[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint120(uint120 val0, uint120 val1, uint120 val2) public { + uint120[] memory input = new uint120[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -487,31 +683,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint240[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint240(); + uint120[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint120(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint248(uint248 val0, uint248 val1, uint248 val2) public { - uint248[] memory input = new uint248[](3); + function encode_uint128(uint128[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 16; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 16; + + return _result; + } + + function testEncodeDecodeArray_uint128(uint128 val0, uint128 val1, uint128 val2) public { + uint128[] memory input = new uint128[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint128(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint248[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint248(); + uint128[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint128(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_uint256(uint256 val0, uint256 val1, uint256 val2) public { - uint256[] memory input = new uint256[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint128(uint128 val0, uint128 val1, uint128 val2) public { + uint128[] memory input = new uint128[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -519,36 +728,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - uint256[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint256(); + uint128[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint128(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - /************************************************************************ - * - * int8 - int256 - * - ************************************************************************/ - function testEncodeDecodeArray_int8(int8 val0, int8 val1, int8 val2) public { - int8[] memory input = new int8[](3); + function encode_uint136(uint136[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 17; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 17; + + return _result; + } + + function testEncodeDecodeArray_uint136(uint136 val0, uint136 val1, uint136 val2) public { + uint136[] memory input = new uint136[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint136(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int8[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int8(); + uint136[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint136(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int16(int16 val0, int16 val1, int16 val2) public { - int16[] memory input = new int16[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint136(uint136 val0, uint136 val1, uint136 val2) public { + uint136[] memory input = new uint136[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -556,31 +773,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int16[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int16(); + uint136[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint136(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int24(int24 val0, int24 val1, int24 val2) public { - int24[] memory input = new int24[](3); + function encode_uint144(uint144[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 18; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 18; + + return _result; + } + + function testEncodeDecodeArray_uint144(uint144 val0, uint144 val1, uint144 val2) public { + uint144[] memory input = new uint144[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint144(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int24[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int24(); + uint144[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint144(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int32(int32 val0, int32 val1, int32 val2) public { - int32[] memory input = new int32[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint144(uint144 val0, uint144 val1, uint144 val2) public { + uint144[] memory input = new uint144[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -588,31 +818,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int32[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int32(); + uint144[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint144(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int40(int40 val0, int40 val1, int40 val2) public { - int40[] memory input = new int40[](3); + function encode_uint152(uint152[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 19; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 19; + + return _result; + } + + function testEncodeDecodeArray_uint152(uint152 val0, uint152 val1, uint152 val2) public { + uint152[] memory input = new uint152[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint152(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int40[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int40(); + uint152[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint152(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int48(int48 val0, int48 val1, int48 val2) public { - int48[] memory input = new int48[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint152(uint152 val0, uint152 val1, uint152 val2) public { + uint152[] memory input = new uint152[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -620,31 +863,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int48[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int48(); + uint152[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint152(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int56(int56 val0, int56 val1, int56 val2) public { - int56[] memory input = new int56[](3); + function encode_uint160(uint160[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 20; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 20; + + return _result; + } + + function testEncodeDecodeArray_uint160(uint160 val0, uint160 val1, uint160 val2) public { + uint160[] memory input = new uint160[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint160(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int56[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int56(); + uint160[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint160(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int64(int64 val0, int64 val1, int64 val2) public { - int64[] memory input = new int64[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint160(uint160 val0, uint160 val1, uint160 val2) public { + uint160[] memory input = new uint160[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -652,31 +908,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int64[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int64(); + uint160[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint160(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int72(int72 val0, int72 val1, int72 val2) public { - int72[] memory input = new int72[](3); + function encode_uint168(uint168[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 21; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 21; + + return _result; + } + + function testEncodeDecodeArray_uint168(uint168 val0, uint168 val1, uint168 val2) public { + uint168[] memory input = new uint168[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint168(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int72[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int72(); + uint168[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint168(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int80(int80 val0, int80 val1, int80 val2) public { - int80[] memory input = new int80[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint168(uint168 val0, uint168 val1, uint168 val2) public { + uint168[] memory input = new uint168[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -684,31 +953,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int80[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int80(); + uint168[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint168(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int88(int88 val0, int88 val1, int88 val2) public { - int88[] memory input = new int88[](3); + function encode_uint176(uint176[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 22; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 22; + + return _result; + } + + function testEncodeDecodeArray_uint176(uint176 val0, uint176 val1, uint176 val2) public { + uint176[] memory input = new uint176[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint176(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int88[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int88(); + uint176[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint176(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int96(int96 val0, int96 val1, int96 val2) public { - int96[] memory input = new int96[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint176(uint176 val0, uint176 val1, uint176 val2) public { + uint176[] memory input = new uint176[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -716,31 +998,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int96[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int96(); + uint176[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint176(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int104(int104 val0, int104 val1, int104 val2) public { - int104[] memory input = new int104[](3); + function encode_uint184(uint184[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 23; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 23; + + return _result; + } + + function testEncodeDecodeArray_uint184(uint184 val0, uint184 val1, uint184 val2) public { + uint184[] memory input = new uint184[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint184(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int104[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int104(); + uint184[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint184(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int112(int112 val0, int112 val1, int112 val2) public { - int112[] memory input = new int112[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint184(uint184 val0, uint184 val1, uint184 val2) public { + uint184[] memory input = new uint184[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -748,31 +1043,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int112[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int112(); + uint184[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint184(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int120(int120 val0, int120 val1, int120 val2) public { - int120[] memory input = new int120[](3); + function encode_uint192(uint192[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 24; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 24; + + return _result; + } + + function testEncodeDecodeArray_uint192(uint192 val0, uint192 val1, uint192 val2) public { + uint192[] memory input = new uint192[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint192(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int120[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int120(); + uint192[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint192(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int128(int128 val0, int128 val1, int128 val2) public { - int128[] memory input = new int128[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint192(uint192 val0, uint192 val1, uint192 val2) public { + uint192[] memory input = new uint192[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -780,31 +1088,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int128[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int128(); + uint192[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint192(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int136(int136 val0, int136 val1, int136 val2) public { - int136[] memory input = new int136[](3); + function encode_uint200(uint200[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 25; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 25; + + return _result; + } + + function testEncodeDecodeArray_uint200(uint200 val0, uint200 val1, uint200 val2) public { + uint200[] memory input = new uint200[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint200(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int136[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int136(); + uint200[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint200(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int144(int144 val0, int144 val1, int144 val2) public { - int144[] memory input = new int144[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint200(uint200 val0, uint200 val1, uint200 val2) public { + uint200[] memory input = new uint200[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -812,31 +1133,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int144[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int144(); + uint200[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint200(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int152(int152 val0, int152 val1, int152 val2) public { - int152[] memory input = new int152[](3); + function encode_uint208(uint208[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 26; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 26; + + return _result; + } + + function testEncodeDecodeArray_uint208(uint208 val0, uint208 val1, uint208 val2) public { + uint208[] memory input = new uint208[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint208(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int152[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int152(); + uint208[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint208(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int160(int160 val0, int160 val1, int160 val2) public { - int160[] memory input = new int160[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint208(uint208 val0, uint208 val1, uint208 val2) public { + uint208[] memory input = new uint208[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -844,31 +1178,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int160[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int160(); + uint208[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint208(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int168(int168 val0, int168 val1, int168 val2) public { - int168[] memory input = new int168[](3); + function encode_uint216(uint216[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 27; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 27; + + return _result; + } + + function testEncodeDecodeArray_uint216(uint216 val0, uint216 val1, uint216 val2) public { + uint216[] memory input = new uint216[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint216(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int168[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int168(); + uint216[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint216(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int176(int176 val0, int176 val1, int176 val2) public { - int176[] memory input = new int176[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint216(uint216 val0, uint216 val1, uint216 val2) public { + uint216[] memory input = new uint216[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -876,31 +1223,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int176[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int176(); + uint216[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint216(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int184(int184 val0, int184 val1, int184 val2) public { - int184[] memory input = new int184[](3); + function encode_uint224(uint224[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 28; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 28; + + return _result; + } + + function testEncodeDecodeArray_uint224(uint224 val0, uint224 val1, uint224 val2) public { + uint224[] memory input = new uint224[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint224(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int184[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int184(); + uint224[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint224(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int192(int192 val0, int192 val1, int192 val2) public { - int192[] memory input = new int192[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint224(uint224 val0, uint224 val1, uint224 val2) public { + uint224[] memory input = new uint224[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -908,31 +1268,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int192[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int192(); + uint224[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint224(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int200(int200 val0, int200 val1, int200 val2) public { - int200[] memory input = new int200[](3); + function encode_uint232(uint232[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 29; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 29; + + return _result; + } + + function testEncodeDecodeArray_uint232(uint232 val0, uint232 val1, uint232 val2) public { + uint232[] memory input = new uint232[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint232(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int200[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int200(); + uint232[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint232(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int208(int208 val0, int208 val1, int208 val2) public { - int208[] memory input = new int208[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint232(uint232 val0, uint232 val1, uint232 val2) public { + uint232[] memory input = new uint232[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -940,31 +1313,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int208[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int208(); + uint232[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint232(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int216(int216 val0, int216 val1, int216 val2) public { - int216[] memory input = new int216[](3); + function encode_uint240(uint240[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 30; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 30; + + return _result; + } + + function testEncodeDecodeArray_uint240(uint240 val0, uint240 val1, uint240 val2) public { + uint240[] memory input = new uint240[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint240(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int216[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int216(); + uint240[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint240(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int224(int224 val0, int224 val1, int224 val2) public { - int224[] memory input = new int224[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint240(uint240 val0, uint240 val1, uint240 val2) public { + uint240[] memory input = new uint240[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -972,31 +1358,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int224[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int224(); + uint240[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint240(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int232(int232 val0, int232 val1, int232 val2) public { - int232[] memory input = new int232[](3); + function encode_uint248(uint248[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 31; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 31; + + return _result; + } + + function testEncodeDecodeArray_uint248(uint248 val0, uint248 val1, uint248 val2) public { + uint248[] memory input = new uint248[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint248(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int232[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int232(); + uint248[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint248(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int240(int240 val0, int240 val1, int240 val2) public { - int240[] memory input = new int240[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint248(uint248 val0, uint248 val1, uint248 val2) public { + uint248[] memory input = new uint248[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1004,31 +1403,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int240[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int240(); + uint248[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint248(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int248(int248 val0, int248 val1, int248 val2) public { - int248[] memory input = new int248[](3); + function encode_uint256(uint256[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 32; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 32; + + return _result; + } + + function testEncodeDecodeArray_uint256(uint256 val0, uint256 val1, uint256 val2) public { + uint256[] memory input = new uint256[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_uint256(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int248[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int248(); + uint256[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint256(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_int256(int256 val0, int256 val1, int256 val2) public { - int256[] memory input = new int256[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_uint256(uint256 val0, uint256 val1, uint256 val2) public { + uint256[] memory input = new uint256[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1036,7 +1448,7 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - int256[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int256(); + uint256[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_uint256(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); @@ -1045,27 +1457,40 @@ contract TightCoderAutoTest is Test { /************************************************************************ * - * bytes1 - bytes32 + * int8 - int256 * ************************************************************************/ - function testEncodeDecodeArray_bytes1(bytes1 val0, bytes1 val1, bytes1 val2) public { - bytes1[] memory input = new bytes1[](3); + function encode_int8(int8[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 1; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 1; + + return _result; + } + + function testEncodeDecodeArray_int8(int8 val0, int8 val1, int8 val2) public { + int8[] memory input = new int8[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_int8(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes1[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes1(); + int8[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int8(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes2(bytes2 val0, bytes2 val1, bytes2 val2) public { - bytes2[] memory input = new bytes2[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_int8(int8 val0, int8 val1, int8 val2) public { + int8[] memory input = new int8[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1073,31 +1498,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes2[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes2(); + int8[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int8(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes3(bytes3 val0, bytes3 val1, bytes3 val2) public { - bytes3[] memory input = new bytes3[](3); + function encode_int16(int16[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 2; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 2; + + return _result; + } + + function testEncodeDecodeArray_int16(int16 val0, int16 val1, int16 val2) public { + int16[] memory input = new int16[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_int16(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes3[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes3(); + int16[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int16(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes4(bytes4 val0, bytes4 val1, bytes4 val2) public { - bytes4[] memory input = new bytes4[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_int16(int16 val0, int16 val1, int16 val2) public { + int16[] memory input = new int16[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1105,31 +1543,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes4[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes4(); + int16[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int16(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes5(bytes5 val0, bytes5 val1, bytes5 val2) public { - bytes5[] memory input = new bytes5[](3); + function encode_int24(int24[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 3; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 3; + + return _result; + } + + function testEncodeDecodeArray_int24(int24 val0, int24 val1, int24 val2) public { + int24[] memory input = new int24[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_int24(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes5[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes5(); + int24[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int24(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes6(bytes6 val0, bytes6 val1, bytes6 val2) public { - bytes6[] memory input = new bytes6[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_int24(int24 val0, int24 val1, int24 val2) public { + int24[] memory input = new int24[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1137,31 +1588,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes6[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes6(); + int24[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int24(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes7(bytes7 val0, bytes7 val1, bytes7 val2) public { - bytes7[] memory input = new bytes7[](3); + function encode_int32(int32[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 4; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 4; + + return _result; + } + + function testEncodeDecodeArray_int32(int32 val0, int32 val1, int32 val2) public { + int32[] memory input = new int32[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_int32(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes7[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes7(); + int32[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int32(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes8(bytes8 val0, bytes8 val1, bytes8 val2) public { - bytes8[] memory input = new bytes8[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_int32(int32 val0, int32 val1, int32 val2) public { + int32[] memory input = new int32[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1169,31 +1633,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes8[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes8(); + int32[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int32(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes9(bytes9 val0, bytes9 val1, bytes9 val2) public { - bytes9[] memory input = new bytes9[](3); + function encode_int40(int40[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 5; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 5; + + return _result; + } + + function testEncodeDecodeArray_int40(int40 val0, int40 val1, int40 val2) public { + int40[] memory input = new int40[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_int40(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes9[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes9(); + int40[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int40(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes10(bytes10 val0, bytes10 val1, bytes10 val2) public { - bytes10[] memory input = new bytes10[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_int40(int40 val0, int40 val1, int40 val2) public { + int40[] memory input = new int40[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1201,31 +1678,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes10[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes10(); + int40[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int40(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes11(bytes11 val0, bytes11 val1, bytes11 val2) public { - bytes11[] memory input = new bytes11[](3); + function encode_int48(int48[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 6; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 6; + + return _result; + } + + function testEncodeDecodeArray_int48(int48 val0, int48 val1, int48 val2) public { + int48[] memory input = new int48[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_int48(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes11[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes11(); + int48[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int48(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes12(bytes12 val0, bytes12 val1, bytes12 val2) public { - bytes12[] memory input = new bytes12[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_int48(int48 val0, int48 val1, int48 val2) public { + int48[] memory input = new int48[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1233,31 +1723,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes12[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes12(); + int48[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int48(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes13(bytes13 val0, bytes13 val1, bytes13 val2) public { - bytes13[] memory input = new bytes13[](3); + function encode_int56(int56[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 7; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 7; + + return _result; + } + + function testEncodeDecodeArray_int56(int56 val0, int56 val1, int56 val2) public { + int56[] memory input = new int56[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_int56(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes13[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes13(); + int56[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int56(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes14(bytes14 val0, bytes14 val1, bytes14 val2) public { - bytes14[] memory input = new bytes14[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_int56(int56 val0, int56 val1, int56 val2) public { + int56[] memory input = new int56[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1265,31 +1768,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes14[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes14(); + int56[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int56(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes15(bytes15 val0, bytes15 val1, bytes15 val2) public { - bytes15[] memory input = new bytes15[](3); + function encode_int64(int64[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 8; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 8; + + return _result; + } + + function testEncodeDecodeArray_int64(int64 val0, int64 val1, int64 val2) public { + int64[] memory input = new int64[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_int64(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes15[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes15(); + int64[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int64(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes16(bytes16 val0, bytes16 val1, bytes16 val2) public { - bytes16[] memory input = new bytes16[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_int64(int64 val0, int64 val1, int64 val2) public { + int64[] memory input = new int64[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1297,31 +1813,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes16[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes16(); + int64[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int64(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes17(bytes17 val0, bytes17 val1, bytes17 val2) public { - bytes17[] memory input = new bytes17[](3); + function encode_int72(int72[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 9; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 9; + + return _result; + } + + function testEncodeDecodeArray_int72(int72 val0, int72 val1, int72 val2) public { + int72[] memory input = new int72[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_int72(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes17[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes17(); + int72[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int72(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes18(bytes18 val0, bytes18 val1, bytes18 val2) public { - bytes18[] memory input = new bytes18[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_int72(int72 val0, int72 val1, int72 val2) public { + int72[] memory input = new int72[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1329,31 +1858,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes18[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes18(); + int72[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int72(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes19(bytes19 val0, bytes19 val1, bytes19 val2) public { - bytes19[] memory input = new bytes19[](3); + function encode_int80(int80[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 10; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 10; + + return _result; + } + + function testEncodeDecodeArray_int80(int80 val0, int80 val1, int80 val2) public { + int80[] memory input = new int80[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_int80(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes19[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes19(); + int80[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int80(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes20(bytes20 val0, bytes20 val1, bytes20 val2) public { - bytes20[] memory input = new bytes20[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_int80(int80 val0, int80 val1, int80 val2) public { + int80[] memory input = new int80[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1361,31 +1903,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes20[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes20(); + int80[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int80(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes21(bytes21 val0, bytes21 val1, bytes21 val2) public { - bytes21[] memory input = new bytes21[](3); + function encode_int88(int88[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 11; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 11; + + return _result; + } + + function testEncodeDecodeArray_int88(int88 val0, int88 val1, int88 val2) public { + int88[] memory input = new int88[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_int88(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes21[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes21(); + int88[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int88(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes22(bytes22 val0, bytes22 val1, bytes22 val2) public { - bytes22[] memory input = new bytes22[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_int88(int88 val0, int88 val1, int88 val2) public { + int88[] memory input = new int88[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1393,31 +1948,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes22[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes22(); + int88[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int88(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes23(bytes23 val0, bytes23 val1, bytes23 val2) public { - bytes23[] memory input = new bytes23[](3); + function encode_int96(int96[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 12; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 12; + + return _result; + } + + function testEncodeDecodeArray_int96(int96 val0, int96 val1, int96 val2) public { + int96[] memory input = new int96[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_int96(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes23[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes23(); + int96[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int96(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes24(bytes24 val0, bytes24 val1, bytes24 val2) public { - bytes24[] memory input = new bytes24[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_int96(int96 val0, int96 val1, int96 val2) public { + int96[] memory input = new int96[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1425,31 +1993,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes24[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes24(); + int96[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int96(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes25(bytes25 val0, bytes25 val1, bytes25 val2) public { - bytes25[] memory input = new bytes25[](3); + function encode_int104(int104[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 13; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 13; + + return _result; + } + + function testEncodeDecodeArray_int104(int104 val0, int104 val1, int104 val2) public { + int104[] memory input = new int104[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_int104(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes25[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes25(); + int104[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int104(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes26(bytes26 val0, bytes26 val1, bytes26 val2) public { - bytes26[] memory input = new bytes26[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_int104(int104 val0, int104 val1, int104 val2) public { + int104[] memory input = new int104[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1457,31 +2038,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes26[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes26(); + int104[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int104(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes27(bytes27 val0, bytes27 val1, bytes27 val2) public { - bytes27[] memory input = new bytes27[](3); + function encode_int112(int112[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 14; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 14; + + return _result; + } + + function testEncodeDecodeArray_int112(int112 val0, int112 val1, int112 val2) public { + int112[] memory input = new int112[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_int112(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes27[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes27(); + int112[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int112(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes28(bytes28 val0, bytes28 val1, bytes28 val2) public { - bytes28[] memory input = new bytes28[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_int112(int112 val0, int112 val1, int112 val2) public { + int112[] memory input = new int112[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1489,31 +2083,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes28[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes28(); + int112[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int112(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes29(bytes29 val0, bytes29 val1, bytes29 val2) public { - bytes29[] memory input = new bytes29[](3); + function encode_int120(int120[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 15; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 15; + + return _result; + } + + function testEncodeDecodeArray_int120(int120 val0, int120 val1, int120 val2) public { + int120[] memory input = new int120[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_int120(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes29[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes29(); + int120[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int120(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes30(bytes30 val0, bytes30 val1, bytes30 val2) public { - bytes30[] memory input = new bytes30[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_int120(int120 val0, int120 val1, int120 val2) public { + int120[] memory input = new int120[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1521,31 +2128,44 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes30[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes30(); + int120[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int120(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes31(bytes31 val0, bytes31 val1, bytes31 val2) public { - bytes31[] memory input = new bytes31[](3); + function encode_int128(int128[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 16; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 16; + + return _result; + } + + function testEncodeDecodeArray_int128(int128 val0, int128 val1, int128 val2) public { + int128[] memory input = new int128[](3); input[0] = val0; input[1] = val1; input[2] = val2; - bytes memory encoded = EncodeArray.encode(input); + bytes memory encoded = encode_int128(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes31[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes31(); + int128[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int128(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); assertEq(decoded[2], val2); } - function testEncodeDecodeArray_bytes32(bytes32 val0, bytes32 val1, bytes32 val2) public { - bytes32[] memory input = new bytes32[](3); + // TODO choose 1 encoder + function testEncodeDecodeArray2_int128(int128 val0, int128 val1, int128 val2) public { + int128[] memory input = new int128[](3); input[0] = val0; input[1] = val1; input[2] = val2; @@ -1553,7 +2173,2172 @@ contract TightCoderAutoTest is Test { bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); - bytes32[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes32(); + int128[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int128(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_int136(int136[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 17; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 17; + + return _result; + } + + function testEncodeDecodeArray_int136(int136 val0, int136 val1, int136 val2) public { + int136[] memory input = new int136[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_int136(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int136[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int136(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_int136(int136 val0, int136 val1, int136 val2) public { + int136[] memory input = new int136[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int136[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int136(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_int144(int144[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 18; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 18; + + return _result; + } + + function testEncodeDecodeArray_int144(int144 val0, int144 val1, int144 val2) public { + int144[] memory input = new int144[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_int144(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int144[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int144(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_int144(int144 val0, int144 val1, int144 val2) public { + int144[] memory input = new int144[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int144[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int144(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_int152(int152[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 19; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 19; + + return _result; + } + + function testEncodeDecodeArray_int152(int152 val0, int152 val1, int152 val2) public { + int152[] memory input = new int152[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_int152(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int152[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int152(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_int152(int152 val0, int152 val1, int152 val2) public { + int152[] memory input = new int152[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int152[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int152(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_int160(int160[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 20; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 20; + + return _result; + } + + function testEncodeDecodeArray_int160(int160 val0, int160 val1, int160 val2) public { + int160[] memory input = new int160[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_int160(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int160[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int160(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_int160(int160 val0, int160 val1, int160 val2) public { + int160[] memory input = new int160[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int160[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int160(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_int168(int168[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 21; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 21; + + return _result; + } + + function testEncodeDecodeArray_int168(int168 val0, int168 val1, int168 val2) public { + int168[] memory input = new int168[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_int168(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int168[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int168(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_int168(int168 val0, int168 val1, int168 val2) public { + int168[] memory input = new int168[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int168[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int168(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_int176(int176[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 22; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 22; + + return _result; + } + + function testEncodeDecodeArray_int176(int176 val0, int176 val1, int176 val2) public { + int176[] memory input = new int176[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_int176(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int176[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int176(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_int176(int176 val0, int176 val1, int176 val2) public { + int176[] memory input = new int176[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int176[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int176(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_int184(int184[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 23; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 23; + + return _result; + } + + function testEncodeDecodeArray_int184(int184 val0, int184 val1, int184 val2) public { + int184[] memory input = new int184[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_int184(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int184[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int184(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_int184(int184 val0, int184 val1, int184 val2) public { + int184[] memory input = new int184[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int184[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int184(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_int192(int192[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 24; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 24; + + return _result; + } + + function testEncodeDecodeArray_int192(int192 val0, int192 val1, int192 val2) public { + int192[] memory input = new int192[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_int192(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int192[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int192(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_int192(int192 val0, int192 val1, int192 val2) public { + int192[] memory input = new int192[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int192[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int192(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_int200(int200[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 25; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 25; + + return _result; + } + + function testEncodeDecodeArray_int200(int200 val0, int200 val1, int200 val2) public { + int200[] memory input = new int200[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_int200(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int200[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int200(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_int200(int200 val0, int200 val1, int200 val2) public { + int200[] memory input = new int200[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int200[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int200(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_int208(int208[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 26; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 26; + + return _result; + } + + function testEncodeDecodeArray_int208(int208 val0, int208 val1, int208 val2) public { + int208[] memory input = new int208[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_int208(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int208[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int208(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_int208(int208 val0, int208 val1, int208 val2) public { + int208[] memory input = new int208[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int208[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int208(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_int216(int216[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 27; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 27; + + return _result; + } + + function testEncodeDecodeArray_int216(int216 val0, int216 val1, int216 val2) public { + int216[] memory input = new int216[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_int216(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int216[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int216(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_int216(int216 val0, int216 val1, int216 val2) public { + int216[] memory input = new int216[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int216[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int216(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_int224(int224[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 28; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 28; + + return _result; + } + + function testEncodeDecodeArray_int224(int224 val0, int224 val1, int224 val2) public { + int224[] memory input = new int224[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_int224(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int224[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int224(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_int224(int224 val0, int224 val1, int224 val2) public { + int224[] memory input = new int224[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int224[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int224(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_int232(int232[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 29; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 29; + + return _result; + } + + function testEncodeDecodeArray_int232(int232 val0, int232 val1, int232 val2) public { + int232[] memory input = new int232[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_int232(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int232[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int232(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_int232(int232 val0, int232 val1, int232 val2) public { + int232[] memory input = new int232[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int232[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int232(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_int240(int240[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 30; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 30; + + return _result; + } + + function testEncodeDecodeArray_int240(int240 val0, int240 val1, int240 val2) public { + int240[] memory input = new int240[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_int240(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int240[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int240(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_int240(int240 val0, int240 val1, int240 val2) public { + int240[] memory input = new int240[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int240[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int240(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_int248(int248[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 31; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 31; + + return _result; + } + + function testEncodeDecodeArray_int248(int248 val0, int248 val1, int248 val2) public { + int248[] memory input = new int248[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_int248(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int248[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int248(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_int248(int248 val0, int248 val1, int248 val2) public { + int248[] memory input = new int248[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int248[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int248(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_int256(int256[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 32; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 32; + + return _result; + } + + function testEncodeDecodeArray_int256(int256 val0, int256 val1, int256 val2) public { + int256[] memory input = new int256[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_int256(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int256[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int256(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_int256(int256 val0, int256 val1, int256 val2) public { + int256[] memory input = new int256[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + int256[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_int256(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + /************************************************************************ + * + * bytes1 - bytes32 + * + ************************************************************************/ + function encode_bytes1(bytes1[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 1; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 1; + + return _result; + } + + function testEncodeDecodeArray_bytes1(bytes1 val0, bytes1 val1, bytes1 val2) public { + bytes1[] memory input = new bytes1[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes1(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes1[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes1(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes1(bytes1 val0, bytes1 val1, bytes1 val2) public { + bytes1[] memory input = new bytes1[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes1[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes1(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes2(bytes2[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 2; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 2; + + return _result; + } + + function testEncodeDecodeArray_bytes2(bytes2 val0, bytes2 val1, bytes2 val2) public { + bytes2[] memory input = new bytes2[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes2(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes2[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes2(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes2(bytes2 val0, bytes2 val1, bytes2 val2) public { + bytes2[] memory input = new bytes2[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes2[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes2(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes3(bytes3[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 3; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 3; + + return _result; + } + + function testEncodeDecodeArray_bytes3(bytes3 val0, bytes3 val1, bytes3 val2) public { + bytes3[] memory input = new bytes3[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes3(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes3[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes3(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes3(bytes3 val0, bytes3 val1, bytes3 val2) public { + bytes3[] memory input = new bytes3[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes3[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes3(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes4(bytes4[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 4; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 4; + + return _result; + } + + function testEncodeDecodeArray_bytes4(bytes4 val0, bytes4 val1, bytes4 val2) public { + bytes4[] memory input = new bytes4[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes4(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes4[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes4(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes4(bytes4 val0, bytes4 val1, bytes4 val2) public { + bytes4[] memory input = new bytes4[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes4[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes4(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes5(bytes5[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 5; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 5; + + return _result; + } + + function testEncodeDecodeArray_bytes5(bytes5 val0, bytes5 val1, bytes5 val2) public { + bytes5[] memory input = new bytes5[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes5(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes5[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes5(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes5(bytes5 val0, bytes5 val1, bytes5 val2) public { + bytes5[] memory input = new bytes5[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes5[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes5(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes6(bytes6[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 6; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 6; + + return _result; + } + + function testEncodeDecodeArray_bytes6(bytes6 val0, bytes6 val1, bytes6 val2) public { + bytes6[] memory input = new bytes6[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes6(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes6[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes6(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes6(bytes6 val0, bytes6 val1, bytes6 val2) public { + bytes6[] memory input = new bytes6[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes6[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes6(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes7(bytes7[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 7; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 7; + + return _result; + } + + function testEncodeDecodeArray_bytes7(bytes7 val0, bytes7 val1, bytes7 val2) public { + bytes7[] memory input = new bytes7[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes7(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes7[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes7(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes7(bytes7 val0, bytes7 val1, bytes7 val2) public { + bytes7[] memory input = new bytes7[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes7[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes7(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes8(bytes8[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 8; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 8; + + return _result; + } + + function testEncodeDecodeArray_bytes8(bytes8 val0, bytes8 val1, bytes8 val2) public { + bytes8[] memory input = new bytes8[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes8(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes8[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes8(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes8(bytes8 val0, bytes8 val1, bytes8 val2) public { + bytes8[] memory input = new bytes8[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes8[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes8(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes9(bytes9[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 9; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 9; + + return _result; + } + + function testEncodeDecodeArray_bytes9(bytes9 val0, bytes9 val1, bytes9 val2) public { + bytes9[] memory input = new bytes9[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes9(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes9[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes9(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes9(bytes9 val0, bytes9 val1, bytes9 val2) public { + bytes9[] memory input = new bytes9[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes9[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes9(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes10(bytes10[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 10; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 10; + + return _result; + } + + function testEncodeDecodeArray_bytes10(bytes10 val0, bytes10 val1, bytes10 val2) public { + bytes10[] memory input = new bytes10[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes10(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes10[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes10(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes10(bytes10 val0, bytes10 val1, bytes10 val2) public { + bytes10[] memory input = new bytes10[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes10[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes10(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes11(bytes11[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 11; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 11; + + return _result; + } + + function testEncodeDecodeArray_bytes11(bytes11 val0, bytes11 val1, bytes11 val2) public { + bytes11[] memory input = new bytes11[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes11(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes11[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes11(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes11(bytes11 val0, bytes11 val1, bytes11 val2) public { + bytes11[] memory input = new bytes11[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes11[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes11(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes12(bytes12[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 12; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 12; + + return _result; + } + + function testEncodeDecodeArray_bytes12(bytes12 val0, bytes12 val1, bytes12 val2) public { + bytes12[] memory input = new bytes12[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes12(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes12[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes12(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes12(bytes12 val0, bytes12 val1, bytes12 val2) public { + bytes12[] memory input = new bytes12[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes12[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes12(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes13(bytes13[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 13; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 13; + + return _result; + } + + function testEncodeDecodeArray_bytes13(bytes13 val0, bytes13 val1, bytes13 val2) public { + bytes13[] memory input = new bytes13[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes13(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes13[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes13(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes13(bytes13 val0, bytes13 val1, bytes13 val2) public { + bytes13[] memory input = new bytes13[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes13[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes13(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes14(bytes14[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 14; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 14; + + return _result; + } + + function testEncodeDecodeArray_bytes14(bytes14 val0, bytes14 val1, bytes14 val2) public { + bytes14[] memory input = new bytes14[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes14(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes14[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes14(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes14(bytes14 val0, bytes14 val1, bytes14 val2) public { + bytes14[] memory input = new bytes14[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes14[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes14(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes15(bytes15[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 15; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 15; + + return _result; + } + + function testEncodeDecodeArray_bytes15(bytes15 val0, bytes15 val1, bytes15 val2) public { + bytes15[] memory input = new bytes15[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes15(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes15[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes15(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes15(bytes15 val0, bytes15 val1, bytes15 val2) public { + bytes15[] memory input = new bytes15[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes15[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes15(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes16(bytes16[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 16; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 16; + + return _result; + } + + function testEncodeDecodeArray_bytes16(bytes16 val0, bytes16 val1, bytes16 val2) public { + bytes16[] memory input = new bytes16[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes16(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes16[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes16(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes16(bytes16 val0, bytes16 val1, bytes16 val2) public { + bytes16[] memory input = new bytes16[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes16[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes16(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes17(bytes17[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 17; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 17; + + return _result; + } + + function testEncodeDecodeArray_bytes17(bytes17 val0, bytes17 val1, bytes17 val2) public { + bytes17[] memory input = new bytes17[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes17(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes17[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes17(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes17(bytes17 val0, bytes17 val1, bytes17 val2) public { + bytes17[] memory input = new bytes17[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes17[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes17(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes18(bytes18[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 18; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 18; + + return _result; + } + + function testEncodeDecodeArray_bytes18(bytes18 val0, bytes18 val1, bytes18 val2) public { + bytes18[] memory input = new bytes18[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes18(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes18[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes18(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes18(bytes18 val0, bytes18 val1, bytes18 val2) public { + bytes18[] memory input = new bytes18[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes18[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes18(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes19(bytes19[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 19; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 19; + + return _result; + } + + function testEncodeDecodeArray_bytes19(bytes19 val0, bytes19 val1, bytes19 val2) public { + bytes19[] memory input = new bytes19[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes19(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes19[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes19(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes19(bytes19 val0, bytes19 val1, bytes19 val2) public { + bytes19[] memory input = new bytes19[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes19[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes19(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes20(bytes20[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 20; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 20; + + return _result; + } + + function testEncodeDecodeArray_bytes20(bytes20 val0, bytes20 val1, bytes20 val2) public { + bytes20[] memory input = new bytes20[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes20(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes20[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes20(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes20(bytes20 val0, bytes20 val1, bytes20 val2) public { + bytes20[] memory input = new bytes20[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes20[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes20(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes21(bytes21[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 21; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 21; + + return _result; + } + + function testEncodeDecodeArray_bytes21(bytes21 val0, bytes21 val1, bytes21 val2) public { + bytes21[] memory input = new bytes21[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes21(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes21[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes21(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes21(bytes21 val0, bytes21 val1, bytes21 val2) public { + bytes21[] memory input = new bytes21[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes21[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes21(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes22(bytes22[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 22; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 22; + + return _result; + } + + function testEncodeDecodeArray_bytes22(bytes22 val0, bytes22 val1, bytes22 val2) public { + bytes22[] memory input = new bytes22[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes22(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes22[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes22(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes22(bytes22 val0, bytes22 val1, bytes22 val2) public { + bytes22[] memory input = new bytes22[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes22[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes22(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes23(bytes23[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 23; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 23; + + return _result; + } + + function testEncodeDecodeArray_bytes23(bytes23 val0, bytes23 val1, bytes23 val2) public { + bytes23[] memory input = new bytes23[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes23(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes23[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes23(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes23(bytes23 val0, bytes23 val1, bytes23 val2) public { + bytes23[] memory input = new bytes23[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes23[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes23(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes24(bytes24[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 24; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 24; + + return _result; + } + + function testEncodeDecodeArray_bytes24(bytes24 val0, bytes24 val1, bytes24 val2) public { + bytes24[] memory input = new bytes24[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes24(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes24[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes24(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes24(bytes24 val0, bytes24 val1, bytes24 val2) public { + bytes24[] memory input = new bytes24[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes24[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes24(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes25(bytes25[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 25; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 25; + + return _result; + } + + function testEncodeDecodeArray_bytes25(bytes25 val0, bytes25 val1, bytes25 val2) public { + bytes25[] memory input = new bytes25[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes25(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes25[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes25(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes25(bytes25 val0, bytes25 val1, bytes25 val2) public { + bytes25[] memory input = new bytes25[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes25[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes25(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes26(bytes26[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 26; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 26; + + return _result; + } + + function testEncodeDecodeArray_bytes26(bytes26 val0, bytes26 val1, bytes26 val2) public { + bytes26[] memory input = new bytes26[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes26(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes26[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes26(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes26(bytes26 val0, bytes26 val1, bytes26 val2) public { + bytes26[] memory input = new bytes26[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes26[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes26(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes27(bytes27[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 27; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 27; + + return _result; + } + + function testEncodeDecodeArray_bytes27(bytes27 val0, bytes27 val1, bytes27 val2) public { + bytes27[] memory input = new bytes27[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes27(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes27[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes27(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes27(bytes27 val0, bytes27 val1, bytes27 val2) public { + bytes27[] memory input = new bytes27[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes27[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes27(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes28(bytes28[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 28; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 28; + + return _result; + } + + function testEncodeDecodeArray_bytes28(bytes28 val0, bytes28 val1, bytes28 val2) public { + bytes28[] memory input = new bytes28[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes28(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes28[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes28(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes28(bytes28 val0, bytes28 val1, bytes28 val2) public { + bytes28[] memory input = new bytes28[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes28[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes28(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes29(bytes29[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 29; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 29; + + return _result; + } + + function testEncodeDecodeArray_bytes29(bytes29 val0, bytes29 val1, bytes29 val2) public { + bytes29[] memory input = new bytes29[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes29(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes29[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes29(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes29(bytes29 val0, bytes29 val1, bytes29 val2) public { + bytes29[] memory input = new bytes29[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes29[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes29(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes30(bytes30[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 30; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 30; + + return _result; + } + + function testEncodeDecodeArray_bytes30(bytes30 val0, bytes30 val1, bytes30 val2) public { + bytes30[] memory input = new bytes30[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes30(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes30[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes30(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes30(bytes30 val0, bytes30 val1, bytes30 val2) public { + bytes30[] memory input = new bytes30[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes30[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes30(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes31(bytes31[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 31; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 31; + + return _result; + } + + function testEncodeDecodeArray_bytes31(bytes31 val0, bytes31 val1, bytes31 val2) public { + bytes31[] memory input = new bytes31[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes31(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes31[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes31(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes31(bytes31 val0, bytes31 val1, bytes31 val2) public { + bytes31[] memory input = new bytes31[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes31[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes31(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + function encode_bytes32(bytes32[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 32; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 32; + + return _result; + } + + function testEncodeDecodeArray_bytes32(bytes32 val0, bytes32 val1, bytes32 val2) public { + bytes32[] memory input = new bytes32[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = encode_bytes32(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes32[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes32(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bytes32(bytes32 val0, bytes32 val1, bytes32 val2) public { + bytes32[] memory input = new bytes32[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + + bytes memory encoded = EncodeArray.encode(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bytes32[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bytes32(); assertEq(decoded.length, 3); assertEq(decoded[0], val0); assertEq(decoded[1], val1); @@ -1566,12 +4351,41 @@ contract TightCoderAutoTest is Test { * ************************************************************************/ + function encode_address(address[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 20; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 20; + + return _result; + } + function testEncodeDecodeArray_address(address val0, address val1, address val2) public { address[] memory input = new address[](3); input[0] = val0; input[1] = val1; input[2] = val2; + bytes memory encoded = encode_address(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + address[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_address(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_address(address val0, address val1, address val2) public { + address[] memory input = new address[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); @@ -1582,12 +4396,41 @@ contract TightCoderAutoTest is Test { assertEq(decoded[2], val2); } + function encode_bool(bool[] memory _value) internal pure returns (bytes memory) { + uint256 _resultLength = 0; + _resultLength += _value.length * 1; + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + + EncodeArray.encodeToLocation(_value, _resultPointer); + _resultPointer += _value.length * 1; + + return _result; + } + function testEncodeDecodeArray_bool(bool val0, bool val1, bool val2) public { bool[] memory input = new bool[](3); input[0] = val0; input[1] = val1; input[2] = val2; + bytes memory encoded = encode_bool(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + bool[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_bool(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_bool(bool val0, bool val1, bool val2) public { + bool[] memory input = new bool[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); diff --git a/packages/store/ts/codegen/tightcoder/abiEncodeTightlyPacked.ts b/packages/store/ts/codegen/tightcoder/abiEncodeTightlyPacked.ts new file mode 100644 index 0000000000..23be7e1b21 --- /dev/null +++ b/packages/store/ts/codegen/tightcoder/abiEncodeTightlyPacked.ts @@ -0,0 +1,58 @@ +import { RenderField, renderArguments } from "@latticexyz/common/codegen"; + +/** + * Render the contents of a solidity function to tightly encode the given tuple. + * This is equivalent to solidity's internal storage packing; or encodePacked if it didn't pad array elements. + * Nested tuples aren't supported (MUD doesn't need them). + */ +export function abiEncodeTightlyPacked(fields: RenderField[]) { + const dynamicFields = fields.filter(({ staticByteLength }) => staticByteLength === 0); + const totalStaticByteLength = fields.reduce((acc, { staticByteLength }) => acc + staticByteLength, 0); + if (dynamicFields.length === 0) { + return ` + return abi.encodePacked(${renderArguments(fields.map(({ name }) => name))}); + `; + } + + let result = `uint256 _resultLength = ${totalStaticByteLength};`; + for (const field of dynamicFields) { + result += `_resultLength += ${renderDynamicByteLength(field)};`; + } + result += ` + bytes memory _result = new bytes(_resultLength); + uint256 _resultPointer = Memory.dataPointer(_result); + `; + for (const field of fields) { + if (field.arrayElement) { + result += ` + EncodeArray.encodeToLocation(${field.name}, _resultPointer); + _resultPointer += ${renderDynamicByteLength(field)}; + `; + } else if (field.isDynamic) { + result += ` + Memory.copy(Memory.dataPointer(${field.name}), _resultPointer, ${renderDynamicByteLength(field)}); + _resultPointer += ${renderDynamicByteLength(field)}; + `; + } else { + result += ` + Memory.mstoreN(${field.name}, _resultPointer, ${field.staticByteLength}); + _resultPointer += ${field.staticByteLength}; + `; + } + } + result += ` + return _result; + `; + + return result; +} + +function renderDynamicByteLength(field: RenderField) { + if (field.arrayElement) { + return `${field.name}.length * ${field.arrayElement.staticByteLength}`; + } else if (field.isDynamic) { + return `${field.name}.length`; + } else { + throw new Error(`Field "${field.name}" is not dynamic`); + } +} diff --git a/packages/store/ts/codegen/tightcoder/renderDecodeSlice.ts b/packages/store/ts/codegen/tightcoder/renderDecodeSlice.ts index 98bea66e6e..3153ab19f6 100644 --- a/packages/store/ts/codegen/tightcoder/renderDecodeSlice.ts +++ b/packages/store/ts/codegen/tightcoder/renderDecodeSlice.ts @@ -11,7 +11,7 @@ export function renderDecodeSlice() { `; for (const prefix of ["uint", "int", "bytes"]) { - const [start, end, step, leftAligned] = prefix === "bytes" ? [1, 32, 1, true] : [8, 256, 8, false]; + const [start, end, step] = prefix === "bytes" ? [1, 32, 1] : [8, 256, 8]; result += ` /************************************************************************ * @@ -21,8 +21,8 @@ export function renderDecodeSlice() { `; for (let i = start; i <= end; i += step) { - const typeId = `${prefix}${i}`; - result += renderTightCoderDecode({ typeId, elementSize: i / step, leftAligned }); + const internalTypeId = `${prefix}${i}`; + result += renderTightCoderDecode({ internalTypeId, staticByteLength: i / step }); } } @@ -34,9 +34,9 @@ export function renderDecodeSlice() { ************************************************************************/ // Note: internally address is right-aligned, like uint160 - ${renderTightCoderDecode({ typeId: "address", elementSize: 20, leftAligned: false })} + ${renderTightCoderDecode({ internalTypeId: "address", staticByteLength: 20 })} - ${renderTightCoderDecode({ typeId: "bool", elementSize: 1, leftAligned: false })} + ${renderTightCoderDecode({ internalTypeId: "bool", staticByteLength: 1 })} } `; diff --git a/packages/store/ts/codegen/tightcoder/renderEncodeArray.ts b/packages/store/ts/codegen/tightcoder/renderEncodeArray.ts index d12c01685c..81d9d8dfaa 100644 --- a/packages/store/ts/codegen/tightcoder/renderEncodeArray.ts +++ b/packages/store/ts/codegen/tightcoder/renderEncodeArray.ts @@ -10,7 +10,7 @@ export function renderEncodeArray() { `; for (const prefix of ["uint", "int", "bytes"]) { - const [start, end, step, leftAligned] = prefix === "bytes" ? [1, 32, 1, true] : [8, 256, 8, false]; + const [start, end, step] = prefix === "bytes" ? [1, 32, 1] : [8, 256, 8]; result += ` /************************************************************************ * @@ -20,8 +20,8 @@ export function renderEncodeArray() { `; for (let i = start; i <= end; i += step) { - const typeId = `${prefix}${i}`; - result += renderTightCoderEncode({ typeId, elementSize: i / step, leftAligned }); + const internalTypeId = `${prefix}${i}`; + result += renderTightCoderEncode({ internalTypeId, staticByteLength: i / step }); } } @@ -33,9 +33,9 @@ export function renderEncodeArray() { ************************************************************************/ // Note: internally address is right-aligned, like uint160 - ${renderTightCoderEncode({ typeId: "address", elementSize: 20, leftAligned: false })} + ${renderTightCoderEncode({ internalTypeId: "address", staticByteLength: 20 })} - ${renderTightCoderEncode({ typeId: "bool", elementSize: 1, leftAligned: false })} + ${renderTightCoderEncode({ internalTypeId: "bool", staticByteLength: 1 })} } `; diff --git a/packages/store/ts/codegen/tightcoder/renderFunctions.ts b/packages/store/ts/codegen/tightcoder/renderFunctions.ts index 0145d5f028..6f7d887f3a 100644 --- a/packages/store/ts/codegen/tightcoder/renderFunctions.ts +++ b/packages/store/ts/codegen/tightcoder/renderFunctions.ts @@ -1,13 +1,17 @@ -export type RenderTighcoderOptions = { - typeId: string; - elementSize: number; - leftAligned: boolean; -}; +import { isLeftAligned, shiftLeftBits } from "@latticexyz/common/codegen"; -export function renderTightCoderDecode({ typeId, elementSize, leftAligned }: RenderTighcoderOptions) { +export function renderTightCoderDecode(element: { internalTypeId: string; staticByteLength: number }) { return ` - function decodeArray_${typeId}(Slice _input) internal pure returns (${typeId}[] memory _output) { - bytes32[] memory _genericArray = TightCoder.decode(_input, ${elementSize}, ${leftAligned}); + function decodeArray_${element.internalTypeId}( + Slice _input + ) internal pure returns ( + ${element.internalTypeId}[] memory _output + ) { + bytes32[] memory _genericArray = TightCoder.decode( + _input, + ${element.staticByteLength}, + ${isLeftAligned(element)} + ); assembly { _output := _genericArray } @@ -15,14 +19,28 @@ export function renderTightCoderDecode({ typeId, elementSize, leftAligned }: Ren `.trim(); } -export function renderTightCoderEncode({ typeId, elementSize, leftAligned }: RenderTighcoderOptions) { +export function renderTightCoderEncode(element: { internalTypeId: string; staticByteLength: number }) { return ` - function encode(${typeId}[] memory _input) internal pure returns (bytes memory _output) { + function encodeToLocation(${element.internalTypeId}[] memory _input, uint256 _toPointer) internal pure { bytes32[] memory _genericArray; assembly { _genericArray := _input } - return TightCoder.encode(_genericArray, ${elementSize}, ${leftAligned}); + TightCoder.encodeToLocation( + _genericArray, + _toPointer, + ${element.staticByteLength}, + ${shiftLeftBits(element)} + ); + } + + function encode(${element.internalTypeId}[] memory _input) internal pure returns (bytes memory _output) { + _output = new bytes(_input.length * ${element.staticByteLength}); + uint256 _toPointer; + assembly { + _toPointer := add(_output, 0x20) + } + encodeToLocation(_input, _toPointer); } `.trim(); } diff --git a/packages/store/ts/codegen/tightcoder/renderTightCoderAutoTest.ts b/packages/store/ts/codegen/tightcoder/renderTightCoderAutoTest.ts index 13b1869a27..e5069eb6bc 100644 --- a/packages/store/ts/codegen/tightcoder/renderTightCoderAutoTest.ts +++ b/packages/store/ts/codegen/tightcoder/renderTightCoderAutoTest.ts @@ -1,7 +1,23 @@ import { renderedSolidityHeader } from "@latticexyz/common/codegen"; +import { AbiTypeToSchemaType } from "@latticexyz/schema-type/deprecated"; +import { abiEncodeTightlyPacked } from "./abiEncodeTightlyPacked"; +import { getSchemaTypeInfo } from "../userType"; export function renderTightCoderAutoTestFunction({ typeId }: { typeId: string }) { + const arrayType = getSchemaTypeInfo(AbiTypeToSchemaType[`${typeId}[]`]); + const arrayElement = getSchemaTypeInfo(AbiTypeToSchemaType[typeId]); return ` + function encode_${typeId}(${typeId}[] memory _value) internal pure returns (bytes memory) { + ${abiEncodeTightlyPacked([ + { + ...arrayType, + name: "_value", + methodNameSuffix: "", + arrayElement, + }, + ])} + } + function testEncodeDecodeArray_${typeId}( ${typeId} val0, ${typeId} val1, @@ -12,6 +28,27 @@ export function renderTightCoderAutoTestFunction({ typeId }: { typeId: string }) input[1] = val1; input[2] = val2; + bytes memory encoded = encode_${typeId}(input); + assertEq(encoded, abi.encodePacked(val0, val1, val2)); + + ${typeId}[] memory decoded = SliceLib.fromBytes(encoded).decodeArray_${typeId}(); + assertEq(decoded.length, 3); + assertEq(decoded[0], val0); + assertEq(decoded[1], val1); + assertEq(decoded[2], val2); + } + + // TODO choose 1 encoder + function testEncodeDecodeArray2_${typeId}( + ${typeId} val0, + ${typeId} val1, + ${typeId} val2 + ) public { + ${typeId}[] memory input = new ${typeId}[](3); + input[0] = val0; + input[1] = val1; + input[2] = val2; + bytes memory encoded = EncodeArray.encode(input); assertEq(encoded, abi.encodePacked(val0, val1, val2)); @@ -30,6 +67,7 @@ export function renderTightCoderAutoTest() { import "forge-std/Test.sol"; import { Bytes } from "../../src/Bytes.sol"; import { EncodeArray } from "../../src/tightcoder/EncodeArray.sol"; + import { Memory } from "../../src/Memory.sol"; import { SliceLib } from "../../src/Slice.sol"; contract TightCoderAutoTest is Test { diff --git a/packages/world/gas-report.json b/packages/world/gas-report.json index 36f0745446..7278ed98f6 100644 --- a/packages/world/gas-report.json +++ b/packages/world/gas-report.json @@ -99,7 +99,7 @@ "file": "test/KeysWithValueModule.t.sol", "test": "testSetAndDeleteRecordHook", "name": "change a record on a table with KeysWithValueModule installed", - "gasUsed": 129713 + "gasUsed": 129451 }, { "file": "test/KeysWithValueModule.t.sol", @@ -309,12 +309,12 @@ "file": "test/WorldDynamicUpdate.t.sol", "test": "testUpdateInField", "name": "updateInField 1 item (cold)", - "gasUsed": 41285 + "gasUsed": 40858 }, { "file": "test/WorldDynamicUpdate.t.sol", "test": "testUpdateInField", "name": "updateInField 1 item (warm)", - "gasUsed": 24487 + "gasUsed": 24060 } ] diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 966bbda4b8..3bd2aadef9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -987,7 +987,7 @@ importers: version: 3.3.7 tsup: specifier: ^6.7.0 - version: 6.7.0(postcss@8.4.23)(typescript@5.1.6) + version: 6.7.0(typescript@5.1.6) tsx: specifier: ^3.12.6 version: 3.12.6 @@ -9039,6 +9039,22 @@ packages: postcss: 8.4.23 dev: true + /postcss-load-config@3.1.4: + resolution: {integrity: sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg==} + engines: {node: '>= 10'} + peerDependencies: + postcss: '>=8.0.9' + ts-node: '>=9.0.0' + peerDependenciesMeta: + postcss: + optional: true + ts-node: + optional: true + dependencies: + lilconfig: 2.1.0 + yaml: 1.10.2 + dev: true + /postcss-load-config@3.1.4(postcss@8.4.23): resolution: {integrity: sha512-6DiM4E7v4coTE4uzA8U//WhtPwyhiim3eyjEMFCnUpzbrkK9wJHgKDT2mR+HbtSrd/NubVaYTOpSpjUl8NQeRg==} engines: {node: '>= 10'} @@ -10623,6 +10639,42 @@ packages: - ts-node dev: true + /tsup@6.7.0(typescript@5.1.6): + resolution: {integrity: sha512-L3o8hGkaHnu5TdJns+mCqFsDBo83bJ44rlK7e6VdanIvpea4ArPcU3swWGsLVbXak1PqQx/V+SSmFPujBK+zEQ==} + engines: {node: '>=14.18'} + hasBin: true + peerDependencies: + '@swc/core': ^1 + postcss: ^8.4.12 + typescript: '>=4.1.0' + peerDependenciesMeta: + '@swc/core': + optional: true + postcss: + optional: true + typescript: + optional: true + dependencies: + bundle-require: 4.0.1(esbuild@0.17.17) + cac: 6.7.14 + chokidar: 3.5.3 + debug: 4.3.4(supports-color@8.1.1) + esbuild: 0.17.17 + execa: 5.1.1 + globby: 11.1.0 + joycon: 3.1.1 + postcss-load-config: 3.1.4 + resolve-from: 5.0.0 + rollup: 3.21.8 + source-map: 0.8.0-beta.0 + sucrase: 3.32.0 + tree-kill: 1.2.2 + typescript: 5.1.6 + transitivePeerDependencies: + - supports-color + - ts-node + dev: true + /tsutils@3.21.0(typescript@5.1.6): resolution: {integrity: sha512-mHKK3iUXL+3UF6xL5k0PEhKRUBKPBCv/+RkEOpjRWxxx27KKRBmmA60A9pgOUvMi8GKhRMPEmjBRPzs2W7O1OA==} engines: {node: '>= 6'}