func (v3c *client) handleLDSResponse(resp *v3discoverypb.DiscoveryResponse) error {
	update, md, err := xdsclient.UnmarshalListener(&xdsclient.UnmarshalOptions{
		Version:         resp.GetVersionInfo(),
		Resources:       resp.GetResources(),
		Logger:          v3c.logger,
		UpdateValidator: v3c.updateValidator,
	})
	v3c.parent.NewListeners(update, md)
	return err
}
handleLDSResponse processes an LDS response received from the management
server. On receipt of a good response, it also invokes the registered watcher
callback.
package v3
import (
	"context"
	"fmt"
	"github.com/golang/protobuf/proto"
	statuspb "google.golang.org/genproto/googleapis/rpc/status"
	"google.golang.org/grpc"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/internal/grpclog"
	"google.golang.org/grpc/internal/pretty"
	"google.golang.org/grpc/xds/internal/version"
	"google.golang.org/grpc/xds/internal/xdsclient"
	v3corepb "github.com/envoyproxy/go-control-plane/envoy/config/core/v3"
	v3adsgrpc "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
	v3discoverypb "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v3"
)
func init() {
	xdsclient.RegisterAPIClientBuilder(clientBuilder{})
}
var (
	resourceTypeToURL = map[xdsclient.ResourceType]string{
		xdsclient.ListenerResource:    version.V3ListenerURL,
		xdsclient.RouteConfigResource: version.V3RouteConfigURL,
		xdsclient.ClusterResource:     version.V3ClusterURL,
		xdsclient.EndpointsResource:   version.V3EndpointsURL,
	}
)
type clientBuilder struct{}
func (clientBuilder) Build(cc *grpc.ClientConn, opts xdsclient.BuildOptions) (xdsclient.APIClient, error) {
	return newClient(cc, opts)
}
func (clientBuilder) Version() version.TransportAPI {
	return version.TransportV3
}
func newClient(cc *grpc.ClientConn, opts xdsclient.BuildOptions) (xdsclient.APIClient, error) {
	nodeProto, ok := opts.NodeProto.(*v3corepb.Node)
	if !ok {
		return nil, fmt.Errorf("xds: unsupported Node proto type: %T, want %T", opts.NodeProto, v3corepb.Node{})
	}
	v3c := &client{
		cc:              cc,
		parent:          opts.Parent,
		nodeProto:       nodeProto,
		logger:          opts.Logger,
		updateValidator: opts.Validator,
	}
	v3c.ctx, v3c.cancelCtx = context.WithCancel(context.Background())
	v3c.TransportHelper = xdsclient.NewTransportHelper(v3c, opts.Logger, opts.Backoff)
	return v3c, nil
}
type adsStream v3adsgrpc.AggregatedDiscoveryService_StreamAggregatedResourcesClient
type client struct {
	*xdsclient.TransportHelper
	ctx       context.Context
	cancelCtx context.CancelFunc
	parent    xdsclient.UpdateHandler
	logger    *grpclog.PrefixLogger
	cc              *grpc.ClientConn
	nodeProto       *v3corepb.Node
	updateValidator xdsclient.UpdateValidatorFunc
}
func (v3c *client) NewStream(ctx context.Context) (grpc.ClientStream, error) {
	return v3adsgrpc.NewAggregatedDiscoveryServiceClient(v3c.cc).StreamAggregatedResources(v3c.ctx, grpc.WaitForReady(true))
}
func (v3c *client) SendRequest(s grpc.ClientStream, resourceNames []string, rType xdsclient.ResourceType, version, nonce, errMsg string) error {
	stream, ok := s.(adsStream)
	if !ok {
		return fmt.Errorf("xds: Attempt to send request on unsupported stream type: %T", s)
	}
	req := &v3discoverypb.DiscoveryRequest{
		Node:          v3c.nodeProto,
		TypeUrl:       resourceTypeToURL[rType],
		ResourceNames: resourceNames,
		VersionInfo:   version,
		ResponseNonce: nonce,
	}
	if errMsg != "" {
		req.ErrorDetail = &statuspb.Status{
			Code: int32(codes.InvalidArgument), Message: errMsg,
		}
	}
	if err := stream.Send(req); err != nil {
		return fmt.Errorf("xds: stream.Send(%+v) failed: %v", req, err)
	}
	v3c.logger.Debugf("ADS request sent: %v", pretty.ToJSON(req))
	return nil
}
func (v3c *client) RecvResponse(s grpc.ClientStream) (proto.Message, error) {
	stream, ok := s.(adsStream)
	if !ok {
		return nil, fmt.Errorf("xds: Attempt to receive response on unsupported stream type: %T", s)
	}
	resp, err := stream.Recv()
	if err != nil {
		v3c.parent.NewConnectionError(err)
		return nil, fmt.Errorf("xds: stream.Recv() failed: %v", err)
	}
	v3c.logger.Infof("ADS response received, type: %v", resp.GetTypeUrl())
	v3c.logger.Debugf("ADS response received: %+v", pretty.ToJSON(resp))
	return resp, nil
}
func (v3c *client) HandleResponse(r proto.Message) (xdsclient.ResourceType, string, string, error) {
	rType := xdsclient.UnknownResource
	resp, ok := r.(*v3discoverypb.DiscoveryResponse)
	if !ok {
		return rType, "", "", fmt.Errorf("xds: unsupported message type: %T", resp)
	}
	var err error
	url := resp.GetTypeUrl()
	switch {
	case xdsclient.IsListenerResource(url):
		err = v3c.handleLDSResponse(resp)
		rType = xdsclient.ListenerResource
	case xdsclient.IsRouteConfigResource(url):
		err = v3c.handleRDSResponse(resp)
		rType = xdsclient.RouteConfigResource
	case xdsclient.IsClusterResource(url):
		err = v3c.handleCDSResponse(resp)
		rType = xdsclient.ClusterResource
	case xdsclient.IsEndpointsResource(url):
		err = v3c.handleEDSResponse(resp)
		rType = xdsclient.EndpointsResource
	default:
		return rType, "", "", xdsclient.ErrResourceTypeUnsupported{
			ErrStr: fmt.Sprintf("Resource type %v unknown in response from server", resp.GetTypeUrl()),
		}
	}
	return rType, resp.GetVersionInfo(), resp.GetNonce(), err
}