pub fn encode_bytes(input: &[u8], out: &mut [u8]) -> usizeExpand description
Encodes the bytes argument for the Solidity ABI.
The result is written to out.
Returns the number of bytes written.
§Important
This function assumes that the encoded bytes argument follows two previous other argument that takes up 32 bytes.
So e.g. function(uint32, bool, bytes) (with uint32 and bool
being of word size 32 bytes). This assumption is made to calculate
the offset word.
§Developer Note
The returned layout will be
[offset (32 bytes)] [len (32 bytes)] [data (padded to 32)]The out byte array needs to be able to hold (in the worst case)
95 bytes more than input.len(). This is because we write the
following to out:
- The offset word → always 32 bytes.
- The length word → always 32 bytes.
- The input itself → exactly
input.len()bytes. - We pad the input to a multiple of 32 → between 0 and 31 extra bytes.