static int readRawVarint32(final InputStream input, final int firstByte) throws IOException
    {
        int result = firstByte & 0x7f;
        int offset = 7;
        for (; offset < 32; offset += 7)
        {
            final int b = input.read();
            if (b == -1)
            {
                throw ProtobufException.truncatedMessage();
            }
            result |= (b & 0x7f) << offset;
            if ((b & 0x80) == 0)
            {
                return result;
            }
        }
        // Keep reading up to 64 bits.
        for (; offset < 64; offset += 7)
        {
            final int b = input.read();
            if (b == -1)
            {
                throw ProtobufException.truncatedMessage();
            }
            if ((b & 0x80) == 0)
            {
                return result;
            }
        }
        throw ProtobufException.malformedVarint();
    }
Reads a varint from the input one byte at a time, so that it does not read any bytes after the end of the varint.
If you simply wrapped the stream in a CodedInput and used {@link #readRawVarint32(InputStream)} then you would
probably end up reading past the end of the varint since CodedInput buffers its input.
protostuff-core/src/main/java/io/protostuff/CodedInput.java