encode method