Design, simulation and optimization of an ultracompact all-optical encoder based on 2D-PC