I'm currently testing a few things using the Solidity assembly. Basically, what I want to do is
- Pack several variables of different type together into one bytes array i.e. similar to what abi.encodePacked would do (I assume)
- Write the opposite code that will split the packed message and extract the original variables
The message layout might be something like this
- 32 bytes :: id
- 20 bytes :: addressA
- 20 bytes :: addressB
- 4 bytes :: nonce
In essence, I would like to pack the above four variable into on single bytes using assembly and return the it from the function. At the other end, I would also like to use some assembly code to extract those four variables from the packed bytes value.
The encode function will be
function(uint256, address, address, uint8)
The decode function will be
function(bytes data) returns(uint256, address, address, uint8
I have done some research about using assembly but unfortunately I couldn't find and easy way to accomplish that.