pack and encode