google.golang.org/grpc@v1.72.2/xds/internal/clients/transport_builder.go (about) 1 /* 2 * 3 * Copyright 2024 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 package clients 20 21 import ( 22 "context" 23 ) 24 25 // TransportBuilder provides the functionality to create a communication 26 // channel to an xDS or LRS server. 27 type TransportBuilder interface { 28 // Build creates a new Transport instance to the server based on the 29 // provided ServerIdentifier. 30 Build(serverIdentifier ServerIdentifier) (Transport, error) 31 } 32 33 // Transport provides the functionality to communicate with an xDS or LRS 34 // server using streaming calls. 35 type Transport interface { 36 // NewStream creates a new streaming call to the server for the specific 37 // RPC method name. The returned Stream interface can be used to send and 38 // receive messages on the stream. 39 NewStream(context.Context, string) (Stream, error) 40 41 // Close closes the Transport. 42 Close() error 43 } 44 45 // Stream provides methods to send and receive messages on a stream. Messages 46 // are represented as a byte slice. 47 type Stream interface { 48 // Send sends the provided message on the stream. 49 Send([]byte) error 50 51 // Recv blocks until the next message is received on the stream. 52 Recv() ([]byte, error) 53 }