manage encode and decode