encode and decode for working with cpt api