optimize the encoding and decoding for id