move port encode/decode to utils