Implementing encode.