Esempio n. 1
0
        public int ReadProtobufVarInt()
        {
            var availableBits = BitsInBuffer + SLED * 8 - Offset;
            // Start by overflowingly reading 32 bits.
            // Reading beyond the buffer contents is safe in this case,
            // because the sled ensures that we stay inside of the buffer.
            var buf = PeekInt(32, true);

            // always take the first bytes; others if necessary
            var result = buf & MSK_1;

            BitStreamUtil.AssertMaxBits(availableBits, 1 * 8);
            if ((buf & MSB_1) != 0)
            {
                result |= (buf & MSK_2) >> 1;
                BitStreamUtil.AssertMaxBits(availableBits, 1 * 8);
                if ((buf & MSB_2) != 0)
                {
                    result |= (buf & MSK_3) >> 2;
                    BitStreamUtil.AssertMaxBits(availableBits, 2 * 8);
                    if ((buf & MSB_3) != 0)
                    {
                        result |= (buf & MSK_4) >> 3;
                        BitStreamUtil.AssertMaxBits(availableBits, 3 * 8);
                        if ((buf & MSB_4) != 0)
                        {
                            // dammit, it's too large (probably negative)
                            // fall back to the slow implementation, that's rare
                            return(BitStreamUtil.ReadProtobufVarIntStub(this));
                        }

                        Advance(4 * 8);
                    }
                    else
                    {
                        Advance(3 * 8);
                    }
                }
                else
                {
                    Advance(2 * 8);
                }
            }
            else
            {
                Advance(1 * 8);
            }

            return(unchecked ((int)result));
        }
Esempio n. 2
0
 public int ReadProtobufVarInt()
 {
     return(BitStreamUtil.ReadProtobufVarIntStub(this));
 }