implement encoder