I've been working on decoding called return values. I've discovered that there's a difference between the encoding using the automatically created getter function of a public state variable and a created getter function. To be specific, the decodeParameter web3.js function works with the created getter function returned encoded data, but not with the automatically created public state variable getter function. I can see that the encoding is done slightly differently in the encoded outputs.
This is the encoded called return value from the public state variable getter function. 0x00000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000724ba66543d0493168fa1f67bde1b4251fc164b5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000035465640000000000000000000000000000000000000000000000000000000000
This is the encoded called return value from the created getter function. 0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000001000000000000000000000000724ba66543d0493168fa1f67bde1b4251fc164b5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000035465640000000000000000000000000000000000000000000000000000000000
The data type being reing returned is a struct as defined below.
The specific information that I entered was: name Ted, candidateAddress 0x724ba66543d0493168fA1F67bde1b4251fC164b5, officeId 1, arrayIndex 0.
I can see these pieces of information in the encoded data in addition to where to start in the memory and the numbers of letters in the string. However, for some reason, one is encoded (i.e. arranged) in a way that is compatible with web3.eth.abi.decodeParameter and the other is not. Can anyone explain why?
I have this working using the created getter function, but I'm just looking for some deeper understanding of Solidity. I would appreciate any advice or comments. Cheers.