remove duplicate encoding helper funcs and move to own package so they can be reused. Signed-off-by: naivewong <867245430@qq.com>