func Varint64(r Reader) (int64, int, error) {
	var x int64
	var n int
	var shift uint
	for n < 10 {
		b, err := r.ReadByte()
		if err != nil {
			return x, n, err
		}
		n++
		x |= (int64(b) & 0x7f) << shift
		shift += 7
		if b&0x80 == 0 {
			neg := b&0x40 != 0
			if n == 10 {
				if !neg {
					if b != 0 {
						return 0, n, moduleError("varint64 value is too large")
					}
				} else {
					if b != 0x7f {
						return 0, n, moduleError("varint64 value is too small")
					}
				}
			} else {
				if neg {
					x |= -1 << shift
				}
			}
			return x, n, nil
		}
	}
	return 0, n, moduleError("varint64 encoding is too long")
}
Varint64 reads variably encoded value.  The number of bytes read is also
returned.
package binary
import (
	"encoding/binary"
	"io"
)
type Reader interface {
	io.Reader
	io.ByteScanner
}
func Uint32(r Reader) (uint32, int, error) {
	b := make([]byte, 4)
	n, err := io.ReadFull(r, b)
	if err != nil {
		return 0, n, err
	}
	return binary.LittleEndian.Uint32(b), n, nil
}
func Uint64(r Reader) (uint64, int, error) {
	b := make([]byte, 8)
	n, err := io.ReadFull(r, b)
	if err != nil {
		return 0, n, err
	}
	return binary.LittleEndian.Uint64(b), n, nil
}
func Varuint1(r Reader) (bool, int, error) {
	var n int
	b, err := r.ReadByte()
	if err != nil {
		return false, n, err
	}
	n++
	if b > 1 {
		return false, n, moduleError("varuint1 value is too large")
	}
	return b == 1, n, nil
}
func Varint7(r Reader) (int8, int, error) {
	var n int
	b, err := r.ReadByte()
	if err != nil {
		return 0, n, err
	}
	n++
	if b&0x80 != 0 {
		return 0, n, moduleError("varint7 encoding is too long")
	}
	if b&0x40 != 0 {
		b |= 0x80
	}
	return int8(b), n, nil
}
func Varint32(r Reader) (int32, int, error) {
	var x int32
	var n int
	var shift uint
	for n < 5 {
		b, err := r.ReadByte()
		if err != nil {
			return x, n, err
		}
		n++
		x |= (int32(b) & 0x7f) << shift
		shift += 7
		if b&0x80 == 0 {
			neg := b&0x40 != 0
			if n == 5 {
				if !neg {
					if b > 7 {
						return 0, n, moduleError("varint32 value is too large")
					}
				} else {
					if b < 0x78 {
						return 0, n, moduleError("varint32 value is too small")
					}
				}
			} else {
				if neg {
					x |= -1 << shift
				}
			}
			return x, n, nil
		}
	}
	return 0, n, moduleError("varint32 encoding is too long")
}