@Test public void testDecodeInt() throws ParseException { decodeIntTest(Integer.MAX_VALUE); decodeIntTest(Integer.MIN_VALUE); decodeIntTest(RANDOM.nextInt()); }
public static int decodeInt(byte[] array, int pos, int len) throws ParseException { int result = 0; int i = pos; int negate = 0; if (array[i] == (byte) '-') { negate = 1; i++; } for (; i < pos + len; i++) { byte b = (byte) (array[i] - '0'); if (b < 0 || b >= 10) { throw new ParseException("Not a decimal value: " + new String(array, pos, len)); } result = b + result * 10; if (result < 0) { if (result == Integer.MIN_VALUE && (i + 1 == pos + len)) { return Integer.MIN_VALUE; } throw new ParseException("Bigger than max int value: " + new String(array, pos, len)); } } return (result ^ -negate) + negate; }
ByteBufStrings { public static int decodeInt(byte[] array, int pos, int len) throws ParseException { int result = 0; int i = pos; int negate = 0; if (array[i] == (byte) '-') { negate = 1; i++; } for (; i < pos + len; i++) { byte b = (byte) (array[i] - '0'); if (b < 0 || b >= 10) { throw new ParseException("Not a decimal value: " + new String(array, pos, len)); } result = b + result * 10; if (result < 0) { if (result == Integer.MIN_VALUE && (i + 1 == pos + len)) { return Integer.MIN_VALUE; } throw new ParseException("Bigger than max int value: " + new String(array, pos, len)); } } return (result ^ -negate) + negate; } }
ByteBufStrings { public static int decodeInt(byte[] array, int pos, int len) throws ParseException { int result = 0; int i = pos; int negate = 0; if (array[i] == (byte) '-') { negate = 1; i++; } for (; i < pos + len; i++) { byte b = (byte) (array[i] - '0'); if (b < 0 || b >= 10) { throw new ParseException("Not a decimal value: " + new String(array, pos, len)); } result = b + result * 10; if (result < 0) { if (result == Integer.MIN_VALUE && (i + 1 == pos + len)) { return Integer.MIN_VALUE; } throw new ParseException("Bigger than max int value: " + new String(array, pos, len)); } } return (result ^ -negate) + negate; }  }
ByteBufStrings { public static int decodeInt(byte[] array, int pos, int len) throws ParseException { int result = 0; int i = pos; int negate = 0; if (array[i] == (byte) '-') { negate = 1; i++; } for (; i < pos + len; i++) { byte b = (byte) (array[i] - '0'); if (b < 0 || b >= 10) { throw new ParseException("Not a decimal value: " + new String(array, pos, len)); } result = b + result * 10; if (result < 0) { if (result == Integer.MIN_VALUE && (i + 1 == pos + len)) { return Integer.MIN_VALUE; } throw new ParseException("Bigger than max int value: " + new String(array, pos, len)); } } return (result ^ -negate) + negate; }  static void encodeAscii(byte[] array, int pos, String string); static byte[] encodeAscii(String string); static void putAscii(ByteBuf buf, String string); static ByteBuf wrapAscii(String string); static String decodeAscii(byte[] array, int pos, int len, char[] tmpBuffer); static String decodeAscii(byte[] array, int pos, int len); static String asAscii(ByteBuf buf); static String decodeAscii(byte[] array); static void toLowerCaseAscii(byte[] bytes, int pos, int len); static void toLowerCaseAscii(byte[] bytes); static void toLowerCaseAscii(ByteBuf buf); static void toUpperCaseAscii(byte[] bytes, int pos, int len); static void toUpperCaseAscii(byte[] bytes); static void toUpperCaseAscii(ByteBuf buf); static boolean equalsLowerCaseAscii(byte[] lowerCasePattern, byte[] array, int offset, int size); static boolean equalsUpperCaseAscii(byte[] upperCasePattern, byte[] array, int offset, int size); static int hashCode(byte[] array, int offset, int size); static int hashCode(byte[] array); static int hashCode(ByteBuf buf); static int hashCodeLowerCaseAscii(byte[] array, int offset, int size); static int hashCodeLowerCaseAscii(byte[] array); static int hashCodeLowerCaseAscii(ByteBuf buf); static int hashCodeUpperCaseAscii(byte[] array, int offset, int size); static int hashCodeUpperCaseAscii(byte[] array); static int hashCodeUpperCaseAscii(ByteBuf buf); static int encodeUtf8(byte[] array, int pos, String string); static int encodeUtf8(byte[] array, int pos, char c); static void putUtf8(ByteBuf buf, String string); static void putUtf8(ByteBuf buf, char c); static ByteBuf wrapUtf8(String string); static int decodeUtf8(byte[] array, int pos, int len, char[] buffer, int to); static String decodeUtf8(byte[] array, int pos, int len, char[] tmpBuffer); static String decodeUtf8(byte[] array, int pos, int len); static String decodeUtf8(ByteBuf buf, char[] tmpBuffer); static String decodeUtf8(ByteBuf buf); static String decodeUtf8(byte[] array); static String asUtf8(ByteBuf buf); static int encodeInt(byte[] array, int pos, int value); static int encodePositiveInt(byte[] array, int pos, int value); static int encodeLong(byte[] array, int pos, long value); static int encodePositiveLong(byte[] array, int pos, long value); static void putInt(ByteBuf buf, int value); static void putPositiveInt(ByteBuf buf, int value); static void putLong(ByteBuf buf, long value); static void putPositiveLong(ByteBuf buf, long value); static ByteBuf wrapInt(int value); static ByteBuf wrapLong(long value); static int decodeInt(byte[] array, int pos, int len); static long decodeLong(byte[] array, int pos, int len); static int decodePositiveInt(byte[] array, int pos, int len); static long decodePositiveLong(byte[] array, int pos, int len); }
ByteBufStrings { public static int decodeInt(byte[] array, int pos, int len) throws ParseException { int result = 0; int i = pos; int negate = 0; if (array[i] == (byte) '-') { negate = 1; i++; } for (; i < pos + len; i++) { byte b = (byte) (array[i] - '0'); if (b < 0 || b >= 10) { throw new ParseException("Not a decimal value: " + new String(array, pos, len)); } result = b + result * 10; if (result < 0) { if (result == Integer.MIN_VALUE && (i + 1 == pos + len)) { return Integer.MIN_VALUE; } throw new ParseException("Bigger than max int value: " + new String(array, pos, len)); } } return (result ^ -negate) + negate; }  static void encodeAscii(byte[] array, int pos, String string); static byte[] encodeAscii(String string); static void putAscii(ByteBuf buf, String string); static ByteBuf wrapAscii(String string); static String decodeAscii(byte[] array, int pos, int len, char[] tmpBuffer); static String decodeAscii(byte[] array, int pos, int len); static String asAscii(ByteBuf buf); static String decodeAscii(byte[] array); static void toLowerCaseAscii(byte[] bytes, int pos, int len); static void toLowerCaseAscii(byte[] bytes); static void toLowerCaseAscii(ByteBuf buf); static void toUpperCaseAscii(byte[] bytes, int pos, int len); static void toUpperCaseAscii(byte[] bytes); static void toUpperCaseAscii(ByteBuf buf); static boolean equalsLowerCaseAscii(byte[] lowerCasePattern, byte[] array, int offset, int size); static boolean equalsUpperCaseAscii(byte[] upperCasePattern, byte[] array, int offset, int size); static int hashCode(byte[] array, int offset, int size); static int hashCode(byte[] array); static int hashCode(ByteBuf buf); static int hashCodeLowerCaseAscii(byte[] array, int offset, int size); static int hashCodeLowerCaseAscii(byte[] array); static int hashCodeLowerCaseAscii(ByteBuf buf); static int hashCodeUpperCaseAscii(byte[] array, int offset, int size); static int hashCodeUpperCaseAscii(byte[] array); static int hashCodeUpperCaseAscii(ByteBuf buf); static int encodeUtf8(byte[] array, int pos, String string); static int encodeUtf8(byte[] array, int pos, char c); static void putUtf8(ByteBuf buf, String string); static void putUtf8(ByteBuf buf, char c); static ByteBuf wrapUtf8(String string); static int decodeUtf8(byte[] array, int pos, int len, char[] buffer, int to); static String decodeUtf8(byte[] array, int pos, int len, char[] tmpBuffer); static String decodeUtf8(byte[] array, int pos, int len); static String decodeUtf8(ByteBuf buf, char[] tmpBuffer); static String decodeUtf8(ByteBuf buf); static String decodeUtf8(byte[] array); static String asUtf8(ByteBuf buf); static int encodeInt(byte[] array, int pos, int value); static int encodePositiveInt(byte[] array, int pos, int value); static int encodeLong(byte[] array, int pos, long value); static int encodePositiveLong(byte[] array, int pos, long value); static void putInt(ByteBuf buf, int value); static void putPositiveInt(ByteBuf buf, int value); static void putLong(ByteBuf buf, long value); static void putPositiveLong(ByteBuf buf, long value); static ByteBuf wrapInt(int value); static ByteBuf wrapLong(long value); static int decodeInt(byte[] array, int pos, int len); static long decodeLong(byte[] array, int pos, int len); static int decodePositiveInt(byte[] array, int pos, int len); static long decodePositiveLong(byte[] array, int pos, int len); static final ParseException READ_PAST_LIMIT; static final ParseException READ_PAST_ARRAY_LENGTH; static final byte CR; static final byte LF; static final byte SP; static final byte HT; }