Use varint for packet id and clean up read/write_packet methods.