This is needed to for a sane BIP143 implementation. Should be exactly equivalent to serializing data into a vector then hashing that vector for all types.