simple encode method