protected void writeLong(long val2) {
   int digits = ParserUtils.digits(val2);
   // starting from the end, write each digit
   for (int i = digits - 1; i >= 0; i--) {
     // write the lowest digit.
     buffer.put(buffer.position() + i, (byte) (val2 % 10 + '0'));
     // remove that digit.
     val2 /= 10;
   }
   assert val2 == 0;
   // move the position to after the digits.
   buffer.position(buffer.position() + digits);
 }