Added a method to encode varints.