docs: static int fillBufferWithDelimitedMessageFrom(InputStream in,
              boolean drainRemainingBytesIfTooLarge,
              LinkedBuffer lb) throws IOException
      {
          final byte[] buf = lb.buffer;
          int offset = lb.start, len = buf.length - offset, read = in.read(buf, offset, len);
  
          if (read < 1)
              throw new EOFException("fillBufferWithDelimitedMessageFrom");
  
          int last = offset + read, size = buf[offset++];
          if (0 != (size & 0x80))
          {
              size = size & 0x7f;
  
              for (int shift = 7;; shift += 7)
              {
                  if (offset == last)
                  {
                      // read too few bytes
                      read = in.read(buf, last, len - (last - lb.start));
                      if (read < 1)
                          throw new EOFException("fillBufferWithDelimitedMessageFrom");
  
                      last += read;
                  }
  
                  byte b = buf[offset++];
                  size |= (b & 0x7f) << shift;
  
                  if (0 == (b & 0x80))
                      break;
  
                  if (shift == 28)
                  {
                      // discard the remaining bytes (5)
                      for (int i = 0;;)
                      {
                          if (offset == last)
                          {
                              // read more
                              read = in.read(buf, last, len - (last - lb.start));
                              if (read < 1)
                                  throw new EOFException("fillBufferWithDelimitedMessageFrom");
  
                              last += read;
                          }
  
                          if (buf[offset++] >= 0)
                              break;
  
                          if (5 == ++i)
                          {
                              // we've already consumed 10 bytes
                              throw ProtobufException.malformedVarint();
                          }
                      }
  
                  }
              }
          }
  
          if (size == 0)
          {
              if (offset != last)
                  throw ProtobufException.misreportedSize();
  
              return size;
          }
  
          if (size < 0)
              throw ProtobufException.negativeSize();
  
          final int partial = last - offset;
          if (partial < size)
          {
              // need to read more
              final int delimSize = offset - lb.start;
              if ((size + delimSize) > len)
              {
                  // too large.
  
                  if (!drainRemainingBytesIfTooLarge)
                      return size;
  
                  // drain the remaining bytes
                  for (int remaining = size - partial; remaining > 0;)
                  {
                      read = in.read(buf, lb.start, Math.min(remaining, len));
                      if (read < 1)
                          throw new EOFException("fillBufferWithDelimitedMessageFrom");
  
                      remaining -= read;
                  }
  
                  return size;
              }
  
              // read the remaining bytes
              fillBufferFrom(in, buf, last, size - partial);
          }
  
          // set the read offset (start of message)
          lb.offset = offset;
  
          return size;
      }