code: 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 = intToBytesNoLeadZeroes(length);
              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");
          }
      }
docs: Integer limitation goes up to 2^31-1 so length can never be bigger than
  MAX_ITEM_LENGTH
  
  @param length
  length
  @param offset
  offset
  @return byte[]