Refactor encode/decode int functions to util.py