This actually took we quite a while because the serialization, Output definitions, and where it is added to the output stream is like 4 different files.
SERIALIZE_METHODS is a macro that writes both nValue and scriptPubKey(including the OP_RETURN and all its data push to the transaction output stream.

GitHub
bitcoin/src/primitives/transaction.h at 919e6d01e93a57d991ed456bc67c43605583ada8 · bitcoin/bitcoin
Bitcoin Core integration/staging tree. Contribute to bitcoin/bitcoin development by creating an account on GitHub.