Added encode method to packets.