Write packet tests and complete encoder