// SPDX-License-Identifier: MIT pragma solidity >=0.8.24; /* Autogenerated file. Do not edit manually. */ // Import store internals import { IStore } from "@latticexyz/store/src/IStore.sol"; import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; import { Bytes } from "@latticexyz/store/src/Bytes.sol"; import { Memory } from "@latticexyz/store/src/Memory.sol"; import { SliceLib } from "@latticexyz/store/src/Slice.sol"; import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; import { Schema } from "@latticexyz/store/src/Schema.sol"; import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; struct TestTableData { uint200 val1; uint8 val2; uint16 val3; bool val4; address val5; string dyn1; bytes dyn2; int16[] dyn3; } library TestTable { // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "app", name: "TestTable", typeId: RESOURCE_TABLE });` ResourceId constant _tableId = ResourceId.wrap(0x74626170700000000000000000000000546573745461626c6500000000000000); FieldLayout constant _fieldLayout = FieldLayout.wrap(0x0031050319010201140000000000000000000000000000000000000000000000); // Hex-encoded key schema of (uint200, uint8) Schema constant _keySchema = Schema.wrap(0x001a020018000000000000000000000000000000000000000000000000000000); // Hex-encoded value schema of (uint200, uint8, uint16, bool, address, string, bytes, int16[]) Schema constant _valueSchema = Schema.wrap(0x003105031800016061c5c4830000000000000000000000000000000000000000); /** * @notice Get the table's key field names. * @return keyNames An array of strings with the names of key fields. */ function getKeyNames() internal pure returns (string[] memory keyNames) { keyNames = new string[](2); keyNames[0] = "key1"; keyNames[1] = "key2"; } /** * @notice Get the table's value field names. * @return fieldNames An array of strings with the names of value fields. */ function getFieldNames() internal pure returns (string[] memory fieldNames) { fieldNames = new string[](8); fieldNames[0] = "val1"; fieldNames[1] = "val2"; fieldNames[2] = "val3"; fieldNames[3] = "val4"; fieldNames[4] = "val5"; fieldNames[5] = "dyn1"; fieldNames[6] = "dyn2"; fieldNames[7] = "dyn3"; } /** * @notice Register the table with its config. */ function register() internal { StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Register the table with its config. */ function _register() internal { StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); } /** * @notice Get val1. */ function getVal1(uint200 key1, uint8 key2) internal view returns (uint200 val1) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); return (uint200(bytes25(_blob))); } /** * @notice Get val1. */ function _getVal1(uint200 key1, uint8 key2) internal view returns (uint200 val1) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); return (uint200(bytes25(_blob))); } /** * @notice Set val1. */ function setVal1(uint200 key1, uint8 key2, uint200 val1) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((val1)), _fieldLayout); } /** * @notice Set val1. */ function _setVal1(uint200 key1, uint8 key2, uint200 val1) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((val1)), _fieldLayout); } /** * @notice Get val2. */ function getVal2(uint200 key1, uint8 key2) internal view returns (uint8 val2) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); return (uint8(bytes1(_blob))); } /** * @notice Get val2. */ function _getVal2(uint200 key1, uint8 key2) internal view returns (uint8 val2) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 1, _fieldLayout); return (uint8(bytes1(_blob))); } /** * @notice Set val2. */ function setVal2(uint200 key1, uint8 key2, uint8 val2) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreSwitch.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((val2)), _fieldLayout); } /** * @notice Set val2. */ function _setVal2(uint200 key1, uint8 key2, uint8 val2) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreCore.setStaticField(_tableId, _keyTuple, 1, abi.encodePacked((val2)), _fieldLayout); } /** * @notice Get val3. */ function getVal3(uint200 key1, uint8 key2) internal view returns (uint16 val3) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); return (uint16(bytes2(_blob))); } /** * @notice Get val3. */ function _getVal3(uint200 key1, uint8 key2) internal view returns (uint16 val3) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 2, _fieldLayout); return (uint16(bytes2(_blob))); } /** * @notice Set val3. */ function setVal3(uint200 key1, uint8 key2, uint16 val3) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreSwitch.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((val3)), _fieldLayout); } /** * @notice Set val3. */ function _setVal3(uint200 key1, uint8 key2, uint16 val3) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreCore.setStaticField(_tableId, _keyTuple, 2, abi.encodePacked((val3)), _fieldLayout); } /** * @notice Get val4. */ function getVal4(uint200 key1, uint8 key2) internal view returns (bool val4) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); return (_toBool(uint8(bytes1(_blob)))); } /** * @notice Get val4. */ function _getVal4(uint200 key1, uint8 key2) internal view returns (bool val4) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 3, _fieldLayout); return (_toBool(uint8(bytes1(_blob)))); } /** * @notice Set val4. */ function setVal4(uint200 key1, uint8 key2, bool val4) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreSwitch.setStaticField(_tableId, _keyTuple, 3, abi.encodePacked((val4)), _fieldLayout); } /** * @notice Set val4. */ function _setVal4(uint200 key1, uint8 key2, bool val4) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreCore.setStaticField(_tableId, _keyTuple, 3, abi.encodePacked((val4)), _fieldLayout); } /** * @notice Get val5. */ function getVal5(uint200 key1, uint8 key2) internal view returns (address val5) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 4, _fieldLayout); return (address(bytes20(_blob))); } /** * @notice Get val5. */ function _getVal5(uint200 key1, uint8 key2) internal view returns (address val5) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 4, _fieldLayout); return (address(bytes20(_blob))); } /** * @notice Set val5. */ function setVal5(uint200 key1, uint8 key2, address val5) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreSwitch.setStaticField(_tableId, _keyTuple, 4, abi.encodePacked((val5)), _fieldLayout); } /** * @notice Set val5. */ function _setVal5(uint200 key1, uint8 key2, address val5) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreCore.setStaticField(_tableId, _keyTuple, 4, abi.encodePacked((val5)), _fieldLayout); } /** * @notice Get dyn1. */ function getDyn1(uint200 key1, uint8 key2) internal view returns (string memory dyn1) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 0); return (string(_blob)); } /** * @notice Get dyn1. */ function _getDyn1(uint200 key1, uint8 key2) internal view returns (string memory dyn1) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 0); return (string(_blob)); } /** * @notice Set dyn1. */ function setDyn1(uint200 key1, uint8 key2, string memory dyn1) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreSwitch.setDynamicField(_tableId, _keyTuple, 0, bytes((dyn1))); } /** * @notice Set dyn1. */ function _setDyn1(uint200 key1, uint8 key2, string memory dyn1) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreCore.setDynamicField(_tableId, _keyTuple, 0, bytes((dyn1))); } /** * @notice Get the length of dyn1. */ function lengthDyn1(uint200 key1, uint8 key2) internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 0); unchecked { return _byteLength / 1; } } /** * @notice Get the length of dyn1. */ function _lengthDyn1(uint200 key1, uint8 key2) internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 0); unchecked { return _byteLength / 1; } } /** * @notice Get an item of dyn1. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. */ function getItemDyn1(uint200 key1, uint8 key2, uint256 _index) internal view returns (string memory) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); unchecked { bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1); return (string(_blob)); } } /** * @notice Get an item of dyn1. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. */ function _getItemDyn1(uint200 key1, uint8 key2, uint256 _index) internal view returns (string memory) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); unchecked { bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 0, _index * 1, (_index + 1) * 1); return (string(_blob)); } } /** * @notice Push a slice to dyn1. */ function pushDyn1(uint200 key1, uint8 key2, string memory _slice) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice))); } /** * @notice Push a slice to dyn1. */ function _pushDyn1(uint200 key1, uint8 key2, string memory _slice) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreCore.pushToDynamicField(_tableId, _keyTuple, 0, bytes((_slice))); } /** * @notice Pop a slice from dyn1. */ function popDyn1(uint200 key1, uint8 key2) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 0, 1); } /** * @notice Pop a slice from dyn1. */ function _popDyn1(uint200 key1, uint8 key2) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreCore.popFromDynamicField(_tableId, _keyTuple, 0, 1); } /** * @notice Update a slice of dyn1 at `_index`. */ function updateDyn1(uint200 key1, uint8 key2, uint256 _index, string memory _slice) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); unchecked { bytes memory _encoded = bytes((_slice)); StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded); } } /** * @notice Update a slice of dyn1 at `_index`. */ function _updateDyn1(uint200 key1, uint8 key2, uint256 _index, string memory _slice) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); unchecked { bytes memory _encoded = bytes((_slice)); StoreCore.spliceDynamicData(_tableId, _keyTuple, 0, uint40(_index * 1), uint40(_encoded.length), _encoded); } } /** * @notice Get dyn2. */ function getDyn2(uint200 key1, uint8 key2) internal view returns (bytes memory dyn2) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 1); return (bytes(_blob)); } /** * @notice Get dyn2. */ function _getDyn2(uint200 key1, uint8 key2) internal view returns (bytes memory dyn2) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 1); return (bytes(_blob)); } /** * @notice Set dyn2. */ function setDyn2(uint200 key1, uint8 key2, bytes memory dyn2) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreSwitch.setDynamicField(_tableId, _keyTuple, 1, bytes((dyn2))); } /** * @notice Set dyn2. */ function _setDyn2(uint200 key1, uint8 key2, bytes memory dyn2) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreCore.setDynamicField(_tableId, _keyTuple, 1, bytes((dyn2))); } /** * @notice Get the length of dyn2. */ function lengthDyn2(uint200 key1, uint8 key2) internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 1); unchecked { return _byteLength / 1; } } /** * @notice Get the length of dyn2. */ function _lengthDyn2(uint200 key1, uint8 key2) internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 1); unchecked { return _byteLength / 1; } } /** * @notice Get an item of dyn2. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. */ function getItemDyn2(uint200 key1, uint8 key2, uint256 _index) internal view returns (bytes memory) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); unchecked { bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 1, (_index + 1) * 1); return (bytes(_blob)); } } /** * @notice Get an item of dyn2. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. */ function _getItemDyn2(uint200 key1, uint8 key2, uint256 _index) internal view returns (bytes memory) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); unchecked { bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 1, _index * 1, (_index + 1) * 1); return (bytes(_blob)); } } /** * @notice Push a slice to dyn2. */ function pushDyn2(uint200 key1, uint8 key2, bytes memory _slice) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 1, bytes((_slice))); } /** * @notice Push a slice to dyn2. */ function _pushDyn2(uint200 key1, uint8 key2, bytes memory _slice) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreCore.pushToDynamicField(_tableId, _keyTuple, 1, bytes((_slice))); } /** * @notice Pop a slice from dyn2. */ function popDyn2(uint200 key1, uint8 key2) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 1, 1); } /** * @notice Pop a slice from dyn2. */ function _popDyn2(uint200 key1, uint8 key2) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreCore.popFromDynamicField(_tableId, _keyTuple, 1, 1); } /** * @notice Update a slice of dyn2 at `_index`. */ function updateDyn2(uint200 key1, uint8 key2, uint256 _index, bytes memory _slice) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); unchecked { bytes memory _encoded = bytes((_slice)); StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 1), uint40(_encoded.length), _encoded); } } /** * @notice Update a slice of dyn2 at `_index`. */ function _updateDyn2(uint200 key1, uint8 key2, uint256 _index, bytes memory _slice) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); unchecked { bytes memory _encoded = bytes((_slice)); StoreCore.spliceDynamicData(_tableId, _keyTuple, 1, uint40(_index * 1), uint40(_encoded.length), _encoded); } } /** * @notice Get dyn3. */ function getDyn3(uint200 key1, uint8 key2) internal view returns (int16[] memory dyn3) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); bytes memory _blob = StoreSwitch.getDynamicField(_tableId, _keyTuple, 2); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_int16()); } /** * @notice Get dyn3. */ function _getDyn3(uint200 key1, uint8 key2) internal view returns (int16[] memory dyn3) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); bytes memory _blob = StoreCore.getDynamicField(_tableId, _keyTuple, 2); return (SliceLib.getSubslice(_blob, 0, _blob.length).decodeArray_int16()); } /** * @notice Set dyn3. */ function setDyn3(uint200 key1, uint8 key2, int16[] memory dyn3) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreSwitch.setDynamicField(_tableId, _keyTuple, 2, EncodeArray.encode((dyn3))); } /** * @notice Set dyn3. */ function _setDyn3(uint200 key1, uint8 key2, int16[] memory dyn3) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreCore.setDynamicField(_tableId, _keyTuple, 2, EncodeArray.encode((dyn3))); } /** * @notice Get the length of dyn3. */ function lengthDyn3(uint200 key1, uint8 key2) internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); uint256 _byteLength = StoreSwitch.getDynamicFieldLength(_tableId, _keyTuple, 2); unchecked { return _byteLength / 2; } } /** * @notice Get the length of dyn3. */ function _lengthDyn3(uint200 key1, uint8 key2) internal view returns (uint256) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); uint256 _byteLength = StoreCore.getDynamicFieldLength(_tableId, _keyTuple, 2); unchecked { return _byteLength / 2; } } /** * @notice Get an item of dyn3. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. */ function getItemDyn3(uint200 key1, uint8 key2, uint256 _index) internal view returns (int16) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); unchecked { bytes memory _blob = StoreSwitch.getDynamicFieldSlice(_tableId, _keyTuple, 2, _index * 2, (_index + 1) * 2); return (int16(uint16(bytes2(_blob)))); } } /** * @notice Get an item of dyn3. * @dev Reverts with Store_IndexOutOfBounds if `_index` is out of bounds for the array. */ function _getItemDyn3(uint200 key1, uint8 key2, uint256 _index) internal view returns (int16) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); unchecked { bytes memory _blob = StoreCore.getDynamicFieldSlice(_tableId, _keyTuple, 2, _index * 2, (_index + 1) * 2); return (int16(uint16(bytes2(_blob)))); } } /** * @notice Push an element to dyn3. */ function pushDyn3(uint200 key1, uint8 key2, int16 _element) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreSwitch.pushToDynamicField(_tableId, _keyTuple, 2, abi.encodePacked((_element))); } /** * @notice Push an element to dyn3. */ function _pushDyn3(uint200 key1, uint8 key2, int16 _element) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreCore.pushToDynamicField(_tableId, _keyTuple, 2, abi.encodePacked((_element))); } /** * @notice Pop an element from dyn3. */ function popDyn3(uint200 key1, uint8 key2) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreSwitch.popFromDynamicField(_tableId, _keyTuple, 2, 2); } /** * @notice Pop an element from dyn3. */ function _popDyn3(uint200 key1, uint8 key2) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreCore.popFromDynamicField(_tableId, _keyTuple, 2, 2); } /** * @notice Update an element of dyn3 at `_index`. */ function updateDyn3(uint200 key1, uint8 key2, uint256 _index, int16 _element) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); unchecked { bytes memory _encoded = abi.encodePacked((_element)); StoreSwitch.spliceDynamicData(_tableId, _keyTuple, 2, uint40(_index * 2), uint40(_encoded.length), _encoded); } } /** * @notice Update an element of dyn3 at `_index`. */ function _updateDyn3(uint200 key1, uint8 key2, uint256 _index, int16 _element) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); unchecked { bytes memory _encoded = abi.encodePacked((_element)); StoreCore.spliceDynamicData(_tableId, _keyTuple, 2, uint40(_index * 2), uint40(_encoded.length), _encoded); } } /** * @notice Get the full data. */ function get(uint200 key1, uint8 key2) internal view returns (TestTableData memory _table) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreSwitch.getRecord( _tableId, _keyTuple, _fieldLayout ); return decode(_staticData, _encodedLengths, _dynamicData); } /** * @notice Get the full data. */ function _get(uint200 key1, uint8 key2) internal view returns (TestTableData memory _table) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); (bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData) = StoreCore.getRecord( _tableId, _keyTuple, _fieldLayout ); return decode(_staticData, _encodedLengths, _dynamicData); } /** * @notice Set the full data using individual values. */ function set( uint200 key1, uint8 key2, uint200 val1, uint8 val2, uint16 val3, bool val4, address val5, string memory dyn1, bytes memory dyn2, int16[] memory dyn3 ) internal { bytes memory _staticData = encodeStatic(val1, val2, val3, val4, val5); EncodedLengths _encodedLengths = encodeLengths(dyn1, dyn2, dyn3); bytes memory _dynamicData = encodeDynamic(dyn1, dyn2, dyn3); bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); } /** * @notice Set the full data using individual values. */ function _set( uint200 key1, uint8 key2, uint200 val1, uint8 val2, uint16 val3, bool val4, address val5, string memory dyn1, bytes memory dyn2, int16[] memory dyn3 ) internal { bytes memory _staticData = encodeStatic(val1, val2, val3, val4, val5); EncodedLengths _encodedLengths = encodeLengths(dyn1, dyn2, dyn3); bytes memory _dynamicData = encodeDynamic(dyn1, dyn2, dyn3); bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** * @notice Set the full data using the data struct. */ function set(uint200 key1, uint8 key2, TestTableData memory _table) internal { bytes memory _staticData = encodeStatic(_table.val1, _table.val2, _table.val3, _table.val4, _table.val5); EncodedLengths _encodedLengths = encodeLengths(_table.dyn1, _table.dyn2, _table.dyn3); bytes memory _dynamicData = encodeDynamic(_table.dyn1, _table.dyn2, _table.dyn3); bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreSwitch.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData); } /** * @notice Set the full data using the data struct. */ function _set(uint200 key1, uint8 key2, TestTableData memory _table) internal { bytes memory _staticData = encodeStatic(_table.val1, _table.val2, _table.val3, _table.val4, _table.val5); EncodedLengths _encodedLengths = encodeLengths(_table.dyn1, _table.dyn2, _table.dyn3); bytes memory _dynamicData = encodeDynamic(_table.dyn1, _table.dyn2, _table.dyn3); bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreCore.setRecord(_tableId, _keyTuple, _staticData, _encodedLengths, _dynamicData, _fieldLayout); } /** * @notice Decode the tightly packed blob of static data using this table's field layout. */ function decodeStatic( bytes memory _blob ) internal pure returns (uint200 val1, uint8 val2, uint16 val3, bool val4, address val5) { val1 = (uint200(Bytes.getBytes25(_blob, 0))); val2 = (uint8(Bytes.getBytes1(_blob, 25))); val3 = (uint16(Bytes.getBytes2(_blob, 26))); val4 = (_toBool(uint8(Bytes.getBytes1(_blob, 28)))); val5 = (address(Bytes.getBytes20(_blob, 29))); } /** * @notice Decode the tightly packed blob of dynamic data using the encoded lengths. */ function decodeDynamic( EncodedLengths _encodedLengths, bytes memory _blob ) internal pure returns (string memory dyn1, bytes memory dyn2, int16[] memory dyn3) { uint256 _start; uint256 _end; unchecked { _end = _encodedLengths.atIndex(0); } dyn1 = (string(SliceLib.getSubslice(_blob, _start, _end).toBytes())); _start = _end; unchecked { _end += _encodedLengths.atIndex(1); } dyn2 = (bytes(SliceLib.getSubslice(_blob, _start, _end).toBytes())); _start = _end; unchecked { _end += _encodedLengths.atIndex(2); } dyn3 = (SliceLib.getSubslice(_blob, _start, _end).decodeArray_int16()); } /** * @notice Decode the tightly packed blobs using this table's field layout. * @param _staticData Tightly packed static fields. * @param _encodedLengths Encoded lengths of dynamic fields. * @param _dynamicData Tightly packed dynamic fields. */ function decode( bytes memory _staticData, EncodedLengths _encodedLengths, bytes memory _dynamicData ) internal pure returns (TestTableData memory _table) { (_table.val1, _table.val2, _table.val3, _table.val4, _table.val5) = decodeStatic(_staticData); (_table.dyn1, _table.dyn2, _table.dyn3) = decodeDynamic(_encodedLengths, _dynamicData); } /** * @notice Delete all data for given keys. */ function deleteRecord(uint200 key1, uint8 key2) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreSwitch.deleteRecord(_tableId, _keyTuple); } /** * @notice Delete all data for given keys. */ function _deleteRecord(uint200 key1, uint8 key2) internal { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); } /** * @notice Tightly pack static (fixed length) data using this table's schema. * @return The static data, encoded into a sequence of bytes. */ function encodeStatic( uint200 val1, uint8 val2, uint16 val3, bool val4, address val5 ) internal pure returns (bytes memory) { return abi.encodePacked(val1, val2, val3, val4, val5); } /** * @notice Tightly pack dynamic data lengths using this table's schema. * @return _encodedLengths The lengths of the dynamic fields (packed into a single bytes32 value). */ function encodeLengths( string memory dyn1, bytes memory dyn2, int16[] memory dyn3 ) internal pure returns (EncodedLengths _encodedLengths) { // Lengths are effectively checked during copy by 2**40 bytes exceeding gas limits unchecked { _encodedLengths = EncodedLengthsLib.pack(bytes(dyn1).length, bytes(dyn2).length, dyn3.length * 2); } } /** * @notice Tightly pack dynamic (variable length) data using this table's schema. * @return The dynamic data, encoded into a sequence of bytes. */ function encodeDynamic( string memory dyn1, bytes memory dyn2, int16[] memory dyn3 ) internal pure returns (bytes memory) { return abi.encodePacked(bytes((dyn1)), bytes((dyn2)), EncodeArray.encode((dyn3))); } /** * @notice Encode all of a record's fields. * @return The static (fixed length) data, encoded into a sequence of bytes. * @return The lengths of the dynamic fields (packed into a single bytes32 value). * @return The dynamic (variable length) data, encoded into a sequence of bytes. */ function encode( uint200 val1, uint8 val2, uint16 val3, bool val4, address val5, string memory dyn1, bytes memory dyn2, int16[] memory dyn3 ) internal pure returns (bytes memory, EncodedLengths, bytes memory) { bytes memory _staticData = encodeStatic(val1, val2, val3, val4, val5); EncodedLengths _encodedLengths = encodeLengths(dyn1, dyn2, dyn3); bytes memory _dynamicData = encodeDynamic(dyn1, dyn2, dyn3); return (_staticData, _encodedLengths, _dynamicData); } /** * @notice Encode keys as a bytes32 array using this table's field layout. */ function encodeKeyTuple(uint200 key1, uint8 key2) internal pure returns (bytes32[] memory) { bytes32[] memory _keyTuple = new bytes32[](2); _keyTuple[0] = bytes32(uint256(key1)); _keyTuple[1] = bytes32(uint256(key2)); return _keyTuple; } } /** * @notice Cast a value to a bool. * @dev Boolean values are encoded as uint8 (1 = true, 0 = false), but Solidity doesn't allow casting between uint8 and bool. * @param value The uint8 value to convert. * @return result The boolean value. */ function _toBool(uint8 value) pure returns (bool result) { assembly { result := value } }