Index
assembly
Assembly videos:
Introduction to Solidity Assembly:
https://youtu.be/BPdc_apZRWM?t=2997 (mload)
function testmloadExtraData(bytes calldata _extraData) external pure returns(uint96 data1, uint data2) {
bytes memory exdata = _extraData;
assembly { // solium-disable-line security/no-inline-assembly
data1 := mload(add(exdata, 0x20))
data2 := mload(add(exdata, 0x40))
}
}
bytes memory exdata = _extraData;
assembly { // solium-disable-line security/no-inline-assembly
data1 := mload(add(exdata, 0x20))
data2 := mload(add(exdata, 0x40))
}
}
If call data is accessed directly it gives following error:
TypeError: Call data elements cannot be accessed directly. Copy to a local variable first or use "calldataload" or "calldatacopy" with manually determined offsets and sizes.
For public visibility:
function testmloadExtraData(bytes memory _extraData) public pure returns(uint96 data1, uint data2) {
assembly { // solium-disable-line security/no-inline-assembly
data1 := mload(add(_extraData, 0x20))
data2 := mload(add(_extraData, 0x40))
}
}