From Bitcoin Core's primitive/transaction.h:
/**
* Basic transaction serialization format:
* - int32_t nVersion
* - std::vector<CTxIn> vin
* - std::vector<CTxOut> vout
* - uint32_t nLockTime
*
* Extended transaction serialization format:
* - int32_t nVersion
* - unsigned char dummy = 0x00
* - unsigned char flags (!= 0)
* - std::vector<CTxIn> vin
* - std::vector<CTxOut> vout
* - if (flags & 1):
* - CTxWitness wit;
* - uint32_t nLockTime
*/
In other words, before the txin count, there is a 0x00 0x01
sequence (which would otherwise be interpreted as a transaction with 0 inputs and 1 output, which cannot be valid), and before the locktime there is a witness record for each input (the txin count is not repeated, it's implicitly assumed to be equal to the txin count given before).