add encode and decode