Given the following set of contracts, the goal is to implement a to-bytes and from-bytes converter for structs to be able to pass them from contract to contract in the form of bytes. Please assume that Storage and Controller contracts have different addresses on the network. StructDefiner is never deployed on its own and is used as a part of Storage or Controller.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
contract StructDefiner {
struct MyStruct {
uint256 someField;
address someAddress;
uint128 someOtherfield;
uint128 oneMoreField;
}
}
contract Storage {
StructDefiner.MyStruct[] internal structs;
function getStructByIdx(uint256 idx) external view returns (bytes memory) {
assembly {
//Your code
}
}
}
contract Controller {
Storage internal storag;
constructor(address _storage) {
storag = Storage(_storage);
}
function getStruct(uint256 idx) public view returns (StructDefiner.MyStruct memory myStruct) {
bytes memory _myStruct = storag.getStructByIdx(idx);
assembly {
//your code
}
}
}
I am a beginner in solidity and assembly language please give me some idea how I can solve this problem.