It's kind of annoying that it's required to get the header size and check for errors prior to encoding the header