// ReadVarUint64 tries to read a uint64 from r.
347796
func ReadVarUint64(r io.Reader) (uint64, error) {
	var result uint64
	var shift uint64
	buf := make([]byte, 1)
	for {
		if _, err := r.Read(buf); err != nil {
			return 0, err
		}
		v := uint64(buf[0])
		result |= (v & 0x7F) << shift
		if v&0x80 == 0 {
			return result, nil
		}
		shift += 7
	}

}
826706
func (r *MemUvarintReader) ReadUvarint() (uint64, error) {
	var x uint64
	var s uint
	var C = r.C
	var S = r.S

	for {
		b := S[C]
		C++

		if b < 0x80 {
			r.C = C

			// why 63?  The original code had an 'i += 1' loop var and
			// checked for i > 9 || i == 9 ...; but, we no longer
			// check for the i var, but instead check here for s,
			// which is incremented by 7.  So, 7*9 == 63.
			//
			// why the "extra" >= check?  The normal case is that s <
			// 63, so we check this single >= guard first so that we
			// hit the normal, nil-error return pathway sooner.
			if s >= 63 && (s > 63 || s == 63 && b > 1) {
				return 0, ErrMemUvarintReaderOverflow
			}

			return x | uint64(b)<<s, nil
		}

		x |= uint64(b&0x7f) << s
		s += 7
	}
}
677782
func (v Value) Uint64() (uint64, error) {
	i, err := strconv.ParseUint(v.String(), 10, 64)
	if err != nil {
		return 0, v.invalidTypeError(err, "uint64")
	}
	return i, nil
}
445838
func ReadUint16(r io.Reader) (uint16, error) {
	var v uint16
	if err := binary.Read(r, binary.BigEndian, &v); err != nil {
		return 0, err
	}

	return v, nil
}
69057
func (r *Store) GetUint64(key string) (uint64, error) {
	v, ok := r.GetEntry(key)
	if !ok {
		return 0, errFindParse.Format("uint64", key)
	}
	return v.Uint64Default(0)
}
1274447
func ReadVarintCode(buf []byte) (int, int, error) {
	num, n := binary.Uvarint(buf)
	if n < 0 {
		return 0, 0, fmt.Errorf("varints larger than uint64 not yet supported")
	}
	return int(num), n, nil
}
38771
func ReadVarInt64(r io.Reader) (int64, error) {
	var result int64
	var shift uint64
	size := uint64(32)
	buf := make([]byte, 1)
	for {
		if _, err := r.Read(buf); err != nil {
			return 0, err
		}
		v := int64(buf[0])
		result |= (v & 0x7F) << shift
		shift += 7
		if v&0x80 == 0 {
			if (shift < size) && (v&0x40 != 0) {
				result |= (^0 << shift)
			}
			return result, nil
		}
	}
}
489340
func NewUint64(val uint64, p *uint64) *Uint64 {
	*p = val
	return (*Uint64)(p)
}
873770
func ReadVarInt(b io.ByteReader) (uint64, error) {
	firstByte, err := b.ReadByte()
	if err != nil {
		return 0, err
	}
	// the first two bits of the first byte encode the length
	len := 1 << ((firstByte & 0xc0) >> 6)
	b1 := firstByte & (0xff - 0xc0)
	if len == 1 {
		return uint64(b1), nil
	}
	b2, err := b.ReadByte()
	if err != nil {
		return 0, err
	}
	if len == 2 {
		return uint64(b2) + uint64(b1)<<8, nil
	}
	b3, err := b.ReadByte()
	if err != nil {
		return 0, err
	}
	b4, err := b.ReadByte()
	if err != nil {
		return 0, err
	}
	if len == 4 {
		return uint64(b4) + uint64(b3)<<8 + uint64(b2)<<16 + uint64(b1)<<24, nil
	}
	b5, err := b.ReadByte()
	if err != nil {
		return 0, err
	}
	b6, err := b.ReadByte()
	if err != nil {
		return 0, err
	}
	b7, err := b.ReadByte()
	if err != nil {
		return 0, err
	}
	b8, err := b.ReadByte()
	if err != nil {
		return 0, err
	}
	return uint64(b8) + uint64(b7)<<8 + uint64(b6)<<16 + uint64(b5)<<24 + uint64(b4)<<32 + uint64(b3)<<40 + uint64(b2)<<48 + uint64(b1)<<56, nil
}
322166
func ReadVarUint32(r io.Reader) (uint32, error) {
	u64, err := ReadVarUint64(r)
	if err != nil {
		return 0, err
	}
	return uint32(u64), nil
}
1302100
func (b *ByteBuf) ReadUInt64() (uint64, error) {
	if b.Readable() < 8 {
		return 0, io.ErrShortBuffer
	}

	b.readerIndex += 8
	return Byte2UInt64(b.buf[b.readerIndex-8 : b.readerIndex]), nil
}
453447
func ReadUint32(r io.Reader) (uint32, error) {
	var v uint32
	if err := binary.Read(r, binary.BigEndian, &v); err != nil {
		return 0, err
	}

	return v, nil
}
1310984
func (p *TCompactProtocol) readVarint64() (int64, error) {
	shift := uint(0)
	result := int64(0)
	for {
		b, err := p.ReadByte()
		if err != nil {
			return 0, err
		}
		result |= int64(b&0x7f) << shift
		if (b & 0x80) != 0x80 {
			break
		}
		shift += 7
	}
	return result, nil
}
240229
func readVarInt(r io.Reader) (uint64, int, error) {
	var b [8]byte
	_, err := io.ReadFull(r, b[0:1])
	if err != nil {
		return 0, 1, err
	}

	var rv uint64
	var n int // number of bytes
	discriminant := uint8(b[0])
	switch discriminant {
	case 0xff:
		n = 9
		_, err := io.ReadFull(r, b[:])
		if err != nil {
			return 0, n, err
		}
		rv = binary.LittleEndian.Uint64(b[:])

		// The encoding is not canonical if the value could have been
		// encoded using fewer bytes
		min := uint64(0x100000000)
		if rv < min {
			return 0, n, fmt.Errorf("readVarInt: %d, %d, %d", rv, discriminant, min)
		}

	case 0xfe:
		n = 5
		_, err := io.ReadFull(r, b[0:4])
		if err != nil {
			return 0, n, err
		}
		rv = uint64(binary.LittleEndian.Uint32(b[:]))

		// The encoding is not canonical if the value could have been
		// encoded using fewer bytes
		min := uint64(0x10000)
		if rv < min {
			return 0, n, fmt.Errorf("readVarInt: %d, %d, %d", rv, discriminant, min)
		}

	case 0xfd:
		n = 3
		_, err := io.ReadFull(r, b[0:2])
		if err != nil {
			return 0, n, err
		}
		rv = uint64(binary.LittleEndian.Uint16(b[:]))

		// The encoding is not canonical if the value could have been
		// encoded using fewer bytes
		min := uint64(0xfd)
		if rv < min {
			return 0, n, fmt.Errorf("readVarInt: %d, %d, %d", rv, discriminant, min)
		}

	default:
		rv = uint64(discriminant)
		n = 1
	}

	return rv, n, nil
}
977384
func (b *ByteBuf) ReadUInt32() (uint32, error) {
	if b.Readable() < 4 {
		return 0, io.ErrShortBuffer
	}

	b.readerIndex += 4
	return Byte2UInt32(b.buf[b.readerIndex-4 : b.readerIndex]), nil
}
755099
func (dec *Decoder) DecodeUint64(v *uint64) error {
	if dec.isPooled == 1 {
		panic(InvalidUsagePooledDecoderError("Invalid usage of pooled decoder"))
	}
	return dec.decodeUint64(v)
}
581708
func UInt64() (i uint64) {
	randomBits(r)
	buf := bytes.NewBuffer(r)
	binary.Read(buf, binary.LittleEndian, &i)
	return i
}