Decode the variable remaining length as defined in MQTT v3.1 specification
(section 2.1).

@return the decoded length or -1 if needed more data to decode the length field.
481043
static int decodeRemainingLenght(ByteBuf in) {
        int multiplier = 1;
        int value = 0;
        byte digit;
        do {
            if (in.readableBytes() < 1) {
                return -1;
            }
            digit = in.readByte();
            value += (digit & 0x7F) * multiplier;
            multiplier *= 128;
        } while ((digit & 0x80) != 0);
        return value;
    }
697865
public long getLength()
  {
    StreamSource indirectSource = _indirectSource;
    
    if (indirectSource != null) {
      return indirectSource.getLength();
    }
    
    TempOutputStream out = _out;
    
    if (out != null) {
      return out.getLength();
    }
    else {
      return -1;
    }
  }
923234
public int encodedTypeLength() {
    int ans = 3; // kind code for TUPLE plus the length
    if (fields != null)
      for (int i = 0; i < fields.length; i++)
        ans += fields[i].encodedTypeLength();
    return ans;
  }
1373898
public int getLength()
  {

    if (m_count == -1)
    {
      short count = 0;

      for (int n = dtm.getFirstAttribute(element); n != -1;
              n = dtm.getNextAttribute(n))
      {
        ++count;
      }

      m_count = count;
    }

    return (int) m_count;
  }
905589
static int getLength(int lenByte, InputStream in) throws IOException {
        int value, tmp;

        tmp = lenByte;
        if ((tmp & 0x080) == 0x00) { // short form, 1 byte datum
            value = tmp;
        } else {                     // long form or indefinite
            tmp &= 0x07f;

            /*
             * NOTE:  tmp == 0 indicates indefinite length encoded data.
             * tmp > 4 indicates more than 4Gb of data.
             */
            if (tmp == 0)
                return -1;
            if (tmp < 0 || tmp > 4)
                throw new IOException("DerInputStream.getLength(): lengthTag="
                    + tmp + ", "
                    + ((tmp < 0) ? "incorrect DER encoding." : "too big."));

            for (value = 0; tmp > 0; tmp --) {
                value <<= 8;
                value += 0x0ff & in.read();
            }
            if (value < 0) {
                throw new IOException("DerInputStream.getLength(): "
                        + "Invalid length bytes");
            }
        }
        return value;
    }
1303808
int guessPayloadLength() {
    int length = 0;
    // It is likely that the String length will be the same as the length in bytes
    // when it has been encoded (to UTF8) plus a small overhead.
    try {
      if (jmo.getPayloadPart().getChoiceField(JsPayloadAccess.PAYLOAD) != JsPayloadAccess.IS_PAYLOAD_EMPTY) {
        String payload = (String)getPayload().getField(JmsTextBodyAccess.BODY_DATA_VALUE);
        if (payload != null) length = payload.length() + 24;
      }
    }
    catch (MFPUnsupportedEncodingRuntimeException e) {
      FFDCFilter.processException(e, "com.ibm.ws.sib.mfp.impl.JsJmsTextMessageImpl.getText", "129");
      // hmm... how do we figure out a reasonable length
    }
    return length;
  }
732865
@Override
  public long length() {
    //The length of a character string is the number of UTF-16 units (not the number of characters)
    long len = 0;
    int pos = offset;

    //set ASCII (<= 127 chars)
    for (; len < length && data[pos] >= 0; ) {
      len++;
      pos++;
    }

    //multi-bytes UTF-8
    while (pos < offset + length) {
      byte firstByte = data[pos++];
      if (firstByte < 0) {
        if (firstByte >> 5 != -2 || (firstByte & 30) == 0) {
          if (firstByte >> 4 == -2) {
            if (pos + 1 < offset + length) {
              pos += 2;
              len++;
            } else {
              throw new UncheckedIOException("invalid UTF8", new CharacterCodingException());
            }
          } else if (firstByte >> 3 != -2) {
            throw new UncheckedIOException("invalid UTF8", new CharacterCodingException());
          } else if (pos + 2 < offset + length) {
            pos += 3;
            len += 2;
          } else {
            //bad truncated UTF8
            pos += offset + length;
            len += 1;
          }
        } else {
          pos++;
          len++;
        }
      } else {
        len++;
      }
    }
    return len;
  }
940823
public function decodeString()
    {
        $len = $this->decodeUint32();
        if ($len === null) {
            return null;
        }
        $value = $this->decodeBytes($len);
        if ($value === null) {
            $this->buffer->unget(pack('N', $len));
            return null;
        }
        return $value;
    }
228736
public int getLength() {
        if (m_last == -1) {
            int node;
            while ((node = m_iter.next()) != DTMAxisIterator.END) {
                m_cachedNodes.addElement(node);
            }
            m_last = m_cachedNodes.size();
        }
        return m_last;
    }
1022290
public int length() {
        Opcode opcode = getOpcode();
        if (opcode == null)
            return 1;

        switch (opcode) {
            case TABLESWITCH: {
                int pad = align(pc + 1) - pc;
                int low = getInt(pad + 4);
                int high = getInt(pad + 8);
                return pad + 12 + 4 * (high - low + 1);
            }
            case LOOKUPSWITCH: {
                int pad = align(pc + 1) - pc;
                int npairs = getInt(pad + 4);
                return pad + 8 + 8 * npairs;

            }
            default:
                return opcode.kind.length;
        }
    }
948474
public int getMessageLength() {
		// Message type
		int messageLength = 1;

		// Number of aliases
		messageLength += 4;

		if (this.aliases != null) {
			for (AttributeAlias alias : this.aliases) {
				// Alias number, name length
				messageLength += 8;
				try {
					messageLength += alias.attributeName.getBytes("UTF-16BE").length;
				} catch (UnsupportedEncodingException e) {
					log.error("Unable to encode strings into UTF-16.");
					e.printStackTrace();
				}
			}
		}

		return messageLength;
	}
1173106
private byte[] fetchDecoderOutput() {
        final CompositeByteBuf decoded = Unpooled.compositeBuffer();
        for (;;) {
            final ByteBuf buf = decoder.readInbound();
            if (buf == null) {
                break;
            }
            if (!buf.isReadable()) {
                buf.release();
                continue;
            }
            decoded.addComponent(true, buf);
        }
        final byte[] ret = ByteBufUtil.getBytes(decoded);
        decoded.release();
        return ret;
    }
37528
private int getMoreData() throws IOException {
        if (noMoreInput) {
            return -1;
        } else {
            byte[] buffer = new byte[1024];
            int bytesRead = input.read(buffer);
            if (bytesRead == -1) {
                noMoreInput = true;
                try {
                    obuffer = cipher.doFinal();
                } catch (IllegalBlockSizeException | BadPaddingException e) {
                    throw new CipherException(e);
                }
                if (obuffer == null) {
                    return -1;
                } else {
                    ostart = 0;
                    return ofinish = obuffer.length;
                }
            } else {
                obuffer = cipher.update(buffer, 0, bytesRead);
                ostart = 0;
                return ofinish = (obuffer == null ? 0 : obuffer.length);
            }
        }
    }
130716
public String getShortString()
    {
        String value = Wire.getShortString(needle, needle.position());
        forward(value.length() + 1);
        return value;
    }
1151157
public int read() throws IOException {
    // Read the next non-whitespace character
    int x;
    do {
      x = in.read();
      if (x == -1) {
        return -1;
      }
    } while (Character.isWhitespace((char) x));
    charCount++;

    // The '=' sign is just padding
    if (x == '=') {
      return -1; // effective end of stream
    }

    // Convert from raw form to 6-bit form
    x = ints[x];

    // Calculate which character we're decoding now
    int mode = (charCount - 1) % 4;

    // First char save all six bits, go for another
    if (mode == 0) {
      carryOver = x & 63;
      return read();
    }
    // Second char use previous six bits and first two new bits,
    // save last four bits
    else if (mode == 1) {
      int decoded = ((carryOver << 2) + (x >> 4)) & 255;
      carryOver = x & 15;
      return decoded;
    }
    // Third char use previous four bits and first four new bits,
    // save last two bits
    else if (mode == 2) {
      int decoded = ((carryOver << 4) + (x >> 2)) & 255;
      carryOver = x & 3;
      return decoded;
    }
    // Fourth char use previous two bits and all six new bits
    else if (mode == 3) {
      int decoded = ((carryOver << 6) + x) & 255;
      return decoded;
    }
    return -1; // can't actually reach this line
  }
965978
public int length() {
        try {
            final StringBuilder s = read(MIN_LENGTH);
            pushBack.append(s);
            return s.length();
        } catch (IOException ex) {
            LOGGER.warn("Oops ", ex);
        }
        return 0;
    }
240159
public int readUnsignedInt() {
        int variableByteDecode = 0;
        byte variableByteShift = 0;

        // check if the continuation bit is set
        while ((this.bufferData[this.bufferPosition] & 0x80) != 0) {
            variableByteDecode |= (this.bufferData[this.bufferPosition++] & 0x7f) << variableByteShift;
            variableByteShift += 7;
        }

        // read the seven data bits from the last byte
        return variableByteDecode | (this.bufferData[this.bufferPosition++] << variableByteShift);
    }