Add methods to encode and decode