Packet encoding refactoring.  Issue #64