write specs, encode and decode methods