code: func ReadVarInt(r io.Reader, pver uint32) (uint64, error) {
  	discriminant, err := binarySerializer.Uint8(r)
  	if err != nil {
  		return 0, err
  	}
  
  	var rv uint64
  	switch discriminant {
  	case 0xff:
  		sv, err := binarySerializer.Uint64(r, littleEndian)
  		if err != nil {
  			return 0, err
  		}
  		rv = sv
  
  		// The encoding is not canonical if the value could have been
  		// encoded using fewer bytes.
  		min := uint64(0x100000000)
  		if rv < min {
  			return 0, messageError("ReadVarInt", fmt.Sprintf(
  				errNonCanonicalVarInt, rv, discriminant, min))
  		}
  
  	case 0xfe:
  		sv, err := binarySerializer.Uint32(r, littleEndian)
  		if err != nil {
  			return 0, err
  		}
  		rv = uint64(sv)
  
  		// The encoding is not canonical if the value could have been
  		// encoded using fewer bytes.
  		min := uint64(0x10000)
  		if rv < min {
  			return 0, messageError("ReadVarInt", fmt.Sprintf(
  				errNonCanonicalVarInt, rv, discriminant, min))
  		}
  
  	case 0xfd:
  		sv, err := binarySerializer.Uint16(r, littleEndian)
  		if err != nil {
  			return 0, err
  		}
  		rv = uint64(sv)
  
  		// The encoding is not canonical if the value could have been
  		// encoded using fewer bytes.
  		min := uint64(0xfd)
  		if rv < min {
  			return 0, messageError("ReadVarInt", fmt.Sprintf(
  				errNonCanonicalVarInt, rv, discriminant, min))
  		}
  
  	default:
  		rv = uint64(discriminant)
  	}
  
  	return rv, nil
  }
docs: // ReadVarInt reads a variable length integer from r and returns it as a uint64.