Added encode method.
Added decode method.