Move event encoding into event.cc, in prep for changing encoding.

#802