Encode and decode frames