code: private byte[] getLengthDescriptor(int length) {
          int c = 0;
          int j = length & 15;
          length = length >> 4;
          int max = 9;
          byte[] result = new byte[max + 1];
          
          while (length > 0) {
              byte b = (byte) (length & 255);
              result[max - c] = b;
              length = length >> 8;
              c++;
          }
          
          byte b = (byte) ((c << 4) + j);
          result[max - c] = b;
          return Arrays.copyOfRange(result, max - c, max + 1);
      }
docs: Returns the length descriptor for a data packet. Length descriptor consists of a descriptor
  length byte whose high nybble is the number of additional bytes in the descriptor and whose
  low nybble is the low nybble of the data length value. The additional descriptor bytes (if
  any) form the rest of the data length value from low byte to high byte.
  
  @param length The length to be encoded.
  @return The length descriptor.