Esempio n. 1
0
        private long ReadZigzag64()
        {
            int i = this._reader.ReadSByte();             // first 7 bits

            i = (i << 7) + this._reader.ReadSByte();      // 14 bits
            i = (i << 7) + this._reader.ReadSByte();      // 21
            i = (i << 7) + this._reader.ReadSByte();

            int ptr    = 4;
            int maxEnd = 11;

            // Ok: couple of bytes more
            long l = i;

            do
            {
                int value = this._reader.ReadSByte();
                ptr++;
                if (value < 0)
                {
                    l = (l << 6) + (value & 0x3F);
                    return(SmileUtil.zigzagDecode(l));
                }
                l = (l << 7) + value;
            } while (ptr < maxEnd);
            throw new FormatException("bad zigzag64");
        }
Esempio n. 2
0
        private int ReadZigzag32()
        {
            int value = this._reader.ReadSByte();
            int i;

            if (value < 0)                // 6 bits
            {
                value &= 0x3F;
            }
            else
            {
                i = this._reader.ReadSByte();
                if (i >= 0)                    // 13 bits
                {
                    value = (value << 7) + i;
                    i     = this._reader.ReadSByte();
                    if (i >= 0)
                    {
                        value = (value << 7) + i;
                        i     = this._reader.ReadSByte();
                        if (i >= 0)
                        {
                            value = (value << 7) + i;
                            // and then we must get negative
                            i = this._reader.ReadSByte();
                            if (i >= 0)
                            {
                                throw new Exception("Corrupt input; 32-bit VInt extends beyond 5 data bytes");
                            }
                        }
                    }
                }
                value = (value << 6) + (i & 0x3F);
            }
            value = SmileUtil.zigzagDecode(value);
            return(value);
        }
Esempio n. 3
0
 private int ReadZigzagNumber(int value)
 {
     return(SmileUtil.zigzagDecode(value));
 }