Extract encoding into a method.