class RLP {

	public static byte[] encodeLength(int length, int offset) {
		if (length < SIZE_THRESHOLD) {
			byte firstByte = (byte) (length + offset);
			return new byte[] { firstByte };
		} else if (length < MAX_ITEM_LENGTH) {
			byte[] binaryLength;
			if (length > 0xFF)
				binaryLength = BigInteger.valueOf(length).toByteArray();
			else
				binaryLength = new byte[] { (byte) length };
			byte firstByte = (byte) (binaryLength.length + offset + SIZE_THRESHOLD - 1);
			return concatenate(new byte[] { firstByte }, binaryLength);
		} else {
			throw new RuntimeException("Input too long");
		}
	}

}