RLP { public static byte[] encodeInt(int singleInt) { if (singleInt <= 0xFF) return encodeByte((byte) singleInt); else if (singleInt <= 0xFFFF) return encodeShort((short) singleInt); else if (singleInt <= 0xFFFFFF) return new byte[] { (byte) (OFFSET_SHORT_ITEM + 3), (byte) (singleInt >>> 16), (byte) (singleInt >>> 8), (byte) singleInt}; else { return new byte[] { (byte) (OFFSET_SHORT_ITEM + 4), (byte) (singleInt >>> 24), (byte) (singleInt >>> 16), (byte) (singleInt >>> 8), (byte) singleInt}; } }  static int decodeInt(byte[] data, int index); static BigInteger decodeBigInteger(byte[] data, int index); static byte[] decodeIP4Bytes(byte[] data, int index); static int getFirstListElement(byte[] payload, int pos); static int getNextElementIndex(byte[] payload, int pos); static void fullTraverse(byte[] msgData, int level, int startPos,
			int endPos, int levelToIndex, Queue<Integer> index); static byte getCommandCode(byte[] data); static RLPList decode2(byte[] msgData); static DecodeResult decode(byte[] data, int pos); static byte[] encode(Object input); static byte[] encodeLength(int length, int offset); static byte[] encodeByte(byte singleByte); static byte[] encodeShort(short singleShort); static byte[] encodeInt(int singleInt); static byte[] encodeString(String srcString); static byte[] encodeBigInteger(BigInteger srcBigInteger); static byte[] encodeElement(byte[] srcData); static byte[] encodeList(byte[]... elements);  }
@Test public void testEncodeInt() { byte[] expected = {(byte)0x80}; byte[] data = RLP.encodeInt(0); assertArrayEquals(expected, data); byte[] expected2 = {(byte)0x78}; data = RLP.encodeInt(120); assertArrayEquals(expected2, data); byte[] expected3 = {(byte)0x81, (byte)0x7F}; data = RLP.encodeInt(127); assertArrayEquals(expected3, data); byte[] expected4 = {(byte)0x82, (byte)0x76, (byte)0x5F}; data = RLP.encodeInt(30303); assertArrayEquals(expected4, data); byte[] expected5 = {(byte)0x82, (byte)0x4E, (byte)0xEA}; data = RLP.encodeInt(20202); assertArrayEquals(expected5, data); byte[] expected6 = {(byte)0x83, 1, 0, 0}; data = RLP.encodeInt(65536); assertArrayEquals(expected6, data); byte[] expected7 = {(byte)0x80}; data = RLP.encodeInt(Integer.MIN_VALUE); assertArrayEquals(expected7, data); byte[] expected8 = {(byte)0x84, (byte)0x7F, (byte)0xFF, (byte)0xFF, (byte)0xFF}; data = RLP.encodeInt(Integer.MAX_VALUE); assertArrayEquals(expected8, data); }