Final buffer size should be payload length + header length