pub fn encode<W: Write>(vec: &[KVal], write: &mut W) -> Result<usize>
Serialize KVals and return bytes_written.