Debian Codegraph @

visionai/apiv1/streaming_client.go

raw
1 // Copyright 2025 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Code generated by protoc-gen-go_gapic. DO NOT EDIT.
16
17 package visionai
18
19 import (
20 "bytes"
21 "context"
22 "errors"
23 "fmt"
24 "log/slog"
25 "math"
26 "net/http"
27 "net/url"
28
29 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
30 visionaipb "cloud.google.com/go/visionai/apiv1/visionaipb"
31 gax "github.com/googleapis/gax-go/v2"
32 "google.golang.org/api/iterator"
33 "google.golang.org/api/option"
34 "google.golang.org/api/option/internaloption"
35 gtransport "google.golang.org/api/transport/grpc"
36 httptransport "google.golang.org/api/transport/http"
37 "google.golang.org/grpc"
38 "google.golang.org/protobuf/encoding/protojson"
39 "google.golang.org/protobuf/proto"
40 )
41
42 var newStreamingClientHook clientHook
43
44 // StreamingCallOptions contains the retry settings for each method of StreamingClient.
45 type StreamingCallOptions struct {
46 SendPackets []gax.CallOption
47 ReceivePackets []gax.CallOption
48 ReceiveEvents []gax.CallOption
49 AcquireLease []gax.CallOption
50 RenewLease []gax.CallOption
51 ReleaseLease []gax.CallOption
52 CancelOperation []gax.CallOption
53 DeleteOperation []gax.CallOption
54 GetOperation []gax.CallOption
55 ListOperations []gax.CallOption
56 }
57
58 func defaultStreamingGRPCClientOptions() []option.ClientOption {
59 return []option.ClientOption{
60 internaloption.WithDefaultEndpoint("visionai.googleapis.com:443"),
61 internaloption.WithDefaultEndpointTemplate("visionai.UNIVERSE_DOMAIN:443"),
62 internaloption.WithDefaultMTLSEndpoint("visionai.mtls.googleapis.com:443"),
63 internaloption.WithDefaultUniverseDomain("googleapis.com"),
64 internaloption.WithDefaultAudience("https://visionai.googleapis.com/"),
65 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
66 internaloption.EnableJwtWithScope(),
67 internaloption.EnableNewAuthLibrary(),
68 option.WithGRPCDialOption(grpc.WithDefaultCallOptions(
69 grpc.MaxCallRecvMsgSize(math.MaxInt32))),
70 }
71 }
72
73 func defaultStreamingCallOptions() *StreamingCallOptions {
74 return &StreamingCallOptions{
75 SendPackets: []gax.CallOption{},
76 ReceivePackets: []gax.CallOption{},
77 ReceiveEvents: []gax.CallOption{},
78 AcquireLease: []gax.CallOption{},
79 RenewLease: []gax.CallOption{},
80 ReleaseLease: []gax.CallOption{},
81 CancelOperation: []gax.CallOption{},
82 DeleteOperation: []gax.CallOption{},
83 GetOperation: []gax.CallOption{},
84 ListOperations: []gax.CallOption{},
85 }
86 }
87
88 func defaultStreamingRESTCallOptions() *StreamingCallOptions {
89 return &StreamingCallOptions{
90 SendPackets: []gax.CallOption{},
91 ReceivePackets: []gax.CallOption{},
92 ReceiveEvents: []gax.CallOption{},
93 AcquireLease: []gax.CallOption{},
94 RenewLease: []gax.CallOption{},
95 ReleaseLease: []gax.CallOption{},
96 CancelOperation: []gax.CallOption{},
97 DeleteOperation: []gax.CallOption{},
98 GetOperation: []gax.CallOption{},
99 ListOperations: []gax.CallOption{},
100 }
101 }
102
103 // internalStreamingClient is an interface that defines the methods available from Vision AI API.
104 type internalStreamingClient interface {
105 Close() error
106 setGoogleClientInfo(...string)
107 Connection() *grpc.ClientConn
108 SendPackets(context.Context, ...gax.CallOption) (visionaipb.StreamingService_SendPacketsClient, error)
109 ReceivePackets(context.Context, ...gax.CallOption) (visionaipb.StreamingService_ReceivePacketsClient, error)
110 ReceiveEvents(context.Context, ...gax.CallOption) (visionaipb.StreamingService_ReceiveEventsClient, error)
111 AcquireLease(context.Context, *visionaipb.AcquireLeaseRequest, ...gax.CallOption) (*visionaipb.Lease, error)
112 RenewLease(context.Context, *visionaipb.RenewLeaseRequest, ...gax.CallOption) (*visionaipb.Lease, error)
113 ReleaseLease(context.Context, *visionaipb.ReleaseLeaseRequest, ...gax.CallOption) (*visionaipb.ReleaseLeaseResponse, error)
114 CancelOperation(context.Context, *longrunningpb.CancelOperationRequest, ...gax.CallOption) error
115 DeleteOperation(context.Context, *longrunningpb.DeleteOperationRequest, ...gax.CallOption) error
116 GetOperation(context.Context, *longrunningpb.GetOperationRequest, ...gax.CallOption) (*longrunningpb.Operation, error)
117 ListOperations(context.Context, *longrunningpb.ListOperationsRequest, ...gax.CallOption) *OperationIterator
118 }
119
120 // StreamingClient is a client for interacting with Vision AI API.
121 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
122 //
123 // Streaming service for receiving and sending packets.
124 type StreamingClient struct {
125 // The internal transport-dependent client.
126 internalClient internalStreamingClient
127
128 // The call options for this service.
129 CallOptions *StreamingCallOptions
130 }
131
132 // Wrapper methods routed to the internal client.
133
134 // Close closes the connection to the API service. The user should invoke this when
135 // the client is no longer required.
136 func (c *StreamingClient) Close() error {
137 return c.internalClient.Close()
138 }
139
140 // setGoogleClientInfo sets the name and version of the application in
141 // the `x-goog-api-client` header passed on each request. Intended for
142 // use by Google-written clients.
143 func (c *StreamingClient) setGoogleClientInfo(keyval ...string) {
144 c.internalClient.setGoogleClientInfo(keyval...)
145 }
146
147 // Connection returns a connection to the API service.
148 //
149 // Deprecated: Connections are now pooled so this method does not always
150 // return the same resource.
151 func (c *StreamingClient) Connection() *grpc.ClientConn {
152 return c.internalClient.Connection()
153 }
154
155 // SendPackets send packets to the series.
156 //
157 // This method is not supported for the REST transport.
158 func (c *StreamingClient) SendPackets(ctx context.Context, opts ...gax.CallOption) (visionaipb.StreamingService_SendPacketsClient, error) {
159 return c.internalClient.SendPackets(ctx, opts...)
160 }
161
162 // ReceivePackets receive packets from the series.
163 //
164 // This method is not supported for the REST transport.
165 func (c *StreamingClient) ReceivePackets(ctx context.Context, opts ...gax.CallOption) (visionaipb.StreamingService_ReceivePacketsClient, error) {
166 return c.internalClient.ReceivePackets(ctx, opts...)
167 }
168
169 // ReceiveEvents receive events given the stream name.
170 //
171 // This method is not supported for the REST transport.
172 func (c *StreamingClient) ReceiveEvents(ctx context.Context, opts ...gax.CallOption) (visionaipb.StreamingService_ReceiveEventsClient, error) {
173 return c.internalClient.ReceiveEvents(ctx, opts...)
174 }
175
176 // AcquireLease acquireLease acquires a lease.
177 func (c *StreamingClient) AcquireLease(ctx context.Context, req *visionaipb.AcquireLeaseRequest, opts ...gax.CallOption) (*visionaipb.Lease, error) {
178 return c.internalClient.AcquireLease(ctx, req, opts...)
179 }
180
181 // RenewLease renewLease renews a lease.
182 func (c *StreamingClient) RenewLease(ctx context.Context, req *visionaipb.RenewLeaseRequest, opts ...gax.CallOption) (*visionaipb.Lease, error) {
183 return c.internalClient.RenewLease(ctx, req, opts...)
184 }
185
186 // ReleaseLease rleaseLease releases a lease.
187 func (c *StreamingClient) ReleaseLease(ctx context.Context, req *visionaipb.ReleaseLeaseRequest, opts ...gax.CallOption) (*visionaipb.ReleaseLeaseResponse, error) {
188 return c.internalClient.ReleaseLease(ctx, req, opts...)
189 }
190
191 // CancelOperation is a utility method from google.longrunning.Operations.
192 func (c *StreamingClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
193 return c.internalClient.CancelOperation(ctx, req, opts...)
194 }
195
196 // DeleteOperation is a utility method from google.longrunning.Operations.
197 func (c *StreamingClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
198 return c.internalClient.DeleteOperation(ctx, req, opts...)
199 }
200
201 // GetOperation is a utility method from google.longrunning.Operations.
202 func (c *StreamingClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
203 return c.internalClient.GetOperation(ctx, req, opts...)
204 }
205
206 // ListOperations is a utility method from google.longrunning.Operations.
207 func (c *StreamingClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
208 return c.internalClient.ListOperations(ctx, req, opts...)
209 }
210
211 // streamingGRPCClient is a client for interacting with Vision AI API over gRPC transport.
212 //
213 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
214 type streamingGRPCClient struct {
215 // Connection pool of gRPC connections to the service.
216 connPool gtransport.ConnPool
217
218 // Points back to the CallOptions field of the containing StreamingClient
219 CallOptions **StreamingCallOptions
220
221 // The gRPC API client.
222 streamingClient visionaipb.StreamingServiceClient
223
224 operationsClient longrunningpb.OperationsClient
225
226 // The x-goog-* metadata to be sent with each request.
227 xGoogHeaders []string
228
229 logger *slog.Logger
230 }
231
232 // NewStreamingClient creates a new streaming service client based on gRPC.
233 // The returned client must be Closed when it is done being used to clean up its underlying connections.
234 //
235 // Streaming service for receiving and sending packets.
236 func NewStreamingClient(ctx context.Context, opts ...option.ClientOption) (*StreamingClient, error) {
237 clientOpts := defaultStreamingGRPCClientOptions()
238 if newStreamingClientHook != nil {
239 hookOpts, err := newStreamingClientHook(ctx, clientHookParams{})
240 if err != nil {
241 return nil, err
242 }
243 clientOpts = append(clientOpts, hookOpts...)
244 }
245
246 connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...)
247 if err != nil {
248 return nil, err
249 }
250 client := StreamingClient{CallOptions: defaultStreamingCallOptions()}
251
252 c := &streamingGRPCClient{
253 connPool: connPool,
254 streamingClient: visionaipb.NewStreamingServiceClient(connPool),
255 CallOptions: &client.CallOptions,
256 logger: internaloption.GetLogger(opts),
257 operationsClient: longrunningpb.NewOperationsClient(connPool),
258 }
259 c.setGoogleClientInfo()
260
261 client.internalClient = c
262
263 return &client, nil
264 }
265
266 // Connection returns a connection to the API service.
267 //
268 // Deprecated: Connections are now pooled so this method does not always
269 // return the same resource.
270 func (c *streamingGRPCClient) Connection() *grpc.ClientConn {
271 return c.connPool.Conn()
272 }
273
274 // setGoogleClientInfo sets the name and version of the application in
275 // the `x-goog-api-client` header passed on each request. Intended for
276 // use by Google-written clients.
277 func (c *streamingGRPCClient) setGoogleClientInfo(keyval ...string) {
278 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
279 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "grpc", grpc.Version, "pb", protoVersion)
280 c.xGoogHeaders = []string{
281 "x-goog-api-client", gax.XGoogHeader(kv...),
282 }
283 }
284
285 // Close closes the connection to the API service. The user should invoke this when
286 // the client is no longer required.
287 func (c *streamingGRPCClient) Close() error {
288 return c.connPool.Close()
289 }
290
291 // Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
292 type streamingRESTClient struct {
293 // The http endpoint to connect to.
294 endpoint string
295
296 // The http client.
297 httpClient *http.Client
298
299 // The x-goog-* headers to be sent with each request.
300 xGoogHeaders []string
301
302 // Points back to the CallOptions field of the containing StreamingClient
303 CallOptions **StreamingCallOptions
304
305 logger *slog.Logger
306 }
307
308 // NewStreamingRESTClient creates a new streaming service rest client.
309 //
310 // Streaming service for receiving and sending packets.
311 func NewStreamingRESTClient(ctx context.Context, opts ...option.ClientOption) (*StreamingClient, error) {
312 clientOpts := append(defaultStreamingRESTClientOptions(), opts...)
313 httpClient, endpoint, err := httptransport.NewClient(ctx, clientOpts...)
314 if err != nil {
315 return nil, err
316 }
317
318 callOpts := defaultStreamingRESTCallOptions()
319 c := &streamingRESTClient{
320 endpoint: endpoint,
321 httpClient: httpClient,
322 CallOptions: &callOpts,
323 logger: internaloption.GetLogger(opts),
324 }
325 c.setGoogleClientInfo()
326
327 return &StreamingClient{internalClient: c, CallOptions: callOpts}, nil
328 }
329
330 func defaultStreamingRESTClientOptions() []option.ClientOption {
331 return []option.ClientOption{
332 internaloption.WithDefaultEndpoint("https://visionai.googleapis.com"),
333 internaloption.WithDefaultEndpointTemplate("https://visionai.UNIVERSE_DOMAIN"),
334 internaloption.WithDefaultMTLSEndpoint("https://visionai.mtls.googleapis.com"),
335 internaloption.WithDefaultUniverseDomain("googleapis.com"),
336 internaloption.WithDefaultAudience("https://visionai.googleapis.com/"),
337 internaloption.WithDefaultScopes(DefaultAuthScopes()...),
338 internaloption.EnableNewAuthLibrary(),
339 }
340 }
341
342 // setGoogleClientInfo sets the name and version of the application in
343 // the `x-goog-api-client` header passed on each request. Intended for
344 // use by Google-written clients.
345 func (c *streamingRESTClient) setGoogleClientInfo(keyval ...string) {
346 kv := append([]string{"gl-go", gax.GoVersion}, keyval...)
347 kv = append(kv, "gapic", getVersionClient(), "gax", gax.Version, "rest", "UNKNOWN", "pb", protoVersion)
348 c.xGoogHeaders = []string{
349 "x-goog-api-client", gax.XGoogHeader(kv...),
350 }
351 }
352
353 // Close closes the connection to the API service. The user should invoke this when
354 // the client is no longer required.
355 func (c *streamingRESTClient) Close() error {
356 // Replace httpClient with nil to force cleanup.
357 c.httpClient = nil
358 return nil
359 }
360
361 // Connection returns a connection to the API service.
362 //
363 // Deprecated: This method always returns nil.
364 func (c *streamingRESTClient) Connection() *grpc.ClientConn {
365 return nil
366 }
367 func (c *streamingGRPCClient) SendPackets(ctx context.Context, opts ...gax.CallOption) (visionaipb.StreamingService_SendPacketsClient, error) {
368 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
369 var resp visionaipb.StreamingService_SendPacketsClient
370 opts = append((*c.CallOptions).SendPackets[0:len((*c.CallOptions).SendPackets):len((*c.CallOptions).SendPackets)], opts...)
371 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
372 var err error
373 c.logger.DebugContext(ctx, "api streaming client request", "serviceName", serviceName, "rpcName", "SendPackets")
374 resp, err = c.streamingClient.SendPackets(ctx, settings.GRPC...)
375 c.logger.DebugContext(ctx, "api streaming client response", "serviceName", serviceName, "rpcName", "SendPackets")
376 return err
377 }, opts...)
378 if err != nil {
379 return nil, err
380 }
381 return resp, nil
382 }
383
384 func (c *streamingGRPCClient) ReceivePackets(ctx context.Context, opts ...gax.CallOption) (visionaipb.StreamingService_ReceivePacketsClient, error) {
385 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
386 var resp visionaipb.StreamingService_ReceivePacketsClient
387 opts = append((*c.CallOptions).ReceivePackets[0:len((*c.CallOptions).ReceivePackets):len((*c.CallOptions).ReceivePackets)], opts...)
388 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
389 var err error
390 c.logger.DebugContext(ctx, "api streaming client request", "serviceName", serviceName, "rpcName", "ReceivePackets")
391 resp, err = c.streamingClient.ReceivePackets(ctx, settings.GRPC...)
392 c.logger.DebugContext(ctx, "api streaming client response", "serviceName", serviceName, "rpcName", "ReceivePackets")
393 return err
394 }, opts...)
395 if err != nil {
396 return nil, err
397 }
398 return resp, nil
399 }
400
401 func (c *streamingGRPCClient) ReceiveEvents(ctx context.Context, opts ...gax.CallOption) (visionaipb.StreamingService_ReceiveEventsClient, error) {
402 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, c.xGoogHeaders...)
403 var resp visionaipb.StreamingService_ReceiveEventsClient
404 opts = append((*c.CallOptions).ReceiveEvents[0:len((*c.CallOptions).ReceiveEvents):len((*c.CallOptions).ReceiveEvents)], opts...)
405 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
406 var err error
407 c.logger.DebugContext(ctx, "api streaming client request", "serviceName", serviceName, "rpcName", "ReceiveEvents")
408 resp, err = c.streamingClient.ReceiveEvents(ctx, settings.GRPC...)
409 c.logger.DebugContext(ctx, "api streaming client response", "serviceName", serviceName, "rpcName", "ReceiveEvents")
410 return err
411 }, opts...)
412 if err != nil {
413 return nil, err
414 }
415 return resp, nil
416 }
417
418 func (c *streamingGRPCClient) AcquireLease(ctx context.Context, req *visionaipb.AcquireLeaseRequest, opts ...gax.CallOption) (*visionaipb.Lease, error) {
419 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "series", url.QueryEscape(req.GetSeries()))}
420
421 hds = append(c.xGoogHeaders, hds...)
422 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
423 opts = append((*c.CallOptions).AcquireLease[0:len((*c.CallOptions).AcquireLease):len((*c.CallOptions).AcquireLease)], opts...)
424 var resp *visionaipb.Lease
425 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
426 var err error
427 resp, err = executeRPC(ctx, c.streamingClient.AcquireLease, req, settings.GRPC, c.logger, "AcquireLease")
428 return err
429 }, opts...)
430 if err != nil {
431 return nil, err
432 }
433 return resp, nil
434 }
435
436 func (c *streamingGRPCClient) RenewLease(ctx context.Context, req *visionaipb.RenewLeaseRequest, opts ...gax.CallOption) (*visionaipb.Lease, error) {
437 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "series", url.QueryEscape(req.GetSeries()))}
438
439 hds = append(c.xGoogHeaders, hds...)
440 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
441 opts = append((*c.CallOptions).RenewLease[0:len((*c.CallOptions).RenewLease):len((*c.CallOptions).RenewLease)], opts...)
442 var resp *visionaipb.Lease
443 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
444 var err error
445 resp, err = executeRPC(ctx, c.streamingClient.RenewLease, req, settings.GRPC, c.logger, "RenewLease")
446 return err
447 }, opts...)
448 if err != nil {
449 return nil, err
450 }
451 return resp, nil
452 }
453
454 func (c *streamingGRPCClient) ReleaseLease(ctx context.Context, req *visionaipb.ReleaseLeaseRequest, opts ...gax.CallOption) (*visionaipb.ReleaseLeaseResponse, error) {
455 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "series", url.QueryEscape(req.GetSeries()))}
456
457 hds = append(c.xGoogHeaders, hds...)
458 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
459 opts = append((*c.CallOptions).ReleaseLease[0:len((*c.CallOptions).ReleaseLease):len((*c.CallOptions).ReleaseLease)], opts...)
460 var resp *visionaipb.ReleaseLeaseResponse
461 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
462 var err error
463 resp, err = executeRPC(ctx, c.streamingClient.ReleaseLease, req, settings.GRPC, c.logger, "ReleaseLease")
464 return err
465 }, opts...)
466 if err != nil {
467 return nil, err
468 }
469 return resp, nil
470 }
471
472 func (c *streamingGRPCClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
473 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
474
475 hds = append(c.xGoogHeaders, hds...)
476 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
477 opts = append((*c.CallOptions).CancelOperation[0:len((*c.CallOptions).CancelOperation):len((*c.CallOptions).CancelOperation)], opts...)
478 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
479 var err error
480 _, err = executeRPC(ctx, c.operationsClient.CancelOperation, req, settings.GRPC, c.logger, "CancelOperation")
481 return err
482 }, opts...)
483 return err
484 }
485
486 func (c *streamingGRPCClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
487 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
488
489 hds = append(c.xGoogHeaders, hds...)
490 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
491 opts = append((*c.CallOptions).DeleteOperation[0:len((*c.CallOptions).DeleteOperation):len((*c.CallOptions).DeleteOperation)], opts...)
492 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
493 var err error
494 _, err = executeRPC(ctx, c.operationsClient.DeleteOperation, req, settings.GRPC, c.logger, "DeleteOperation")
495 return err
496 }, opts...)
497 return err
498 }
499
500 func (c *streamingGRPCClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
501 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
502
503 hds = append(c.xGoogHeaders, hds...)
504 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
505 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
506 var resp *longrunningpb.Operation
507 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
508 var err error
509 resp, err = executeRPC(ctx, c.operationsClient.GetOperation, req, settings.GRPC, c.logger, "GetOperation")
510 return err
511 }, opts...)
512 if err != nil {
513 return nil, err
514 }
515 return resp, nil
516 }
517
518 func (c *streamingGRPCClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
519 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
520
521 hds = append(c.xGoogHeaders, hds...)
522 ctx = gax.InsertMetadataIntoOutgoingContext(ctx, hds...)
523 opts = append((*c.CallOptions).ListOperations[0:len((*c.CallOptions).ListOperations):len((*c.CallOptions).ListOperations)], opts...)
524 it := &OperationIterator{}
525 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
526 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
527 resp := &longrunningpb.ListOperationsResponse{}
528 if pageToken != "" {
529 req.PageToken = pageToken
530 }
531 if pageSize > math.MaxInt32 {
532 req.PageSize = math.MaxInt32
533 } else if pageSize != 0 {
534 req.PageSize = int32(pageSize)
535 }
536 err := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
537 var err error
538 resp, err = executeRPC(ctx, c.operationsClient.ListOperations, req, settings.GRPC, c.logger, "ListOperations")
539 return err
540 }, opts...)
541 if err != nil {
542 return nil, "", err
543 }
544
545 it.Response = resp
546 return resp.GetOperations(), resp.GetNextPageToken(), nil
547 }
548 fetch := func(pageSize int, pageToken string) (string, error) {
549 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
550 if err != nil {
551 return "", err
552 }
553 it.items = append(it.items, items...)
554 return nextPageToken, nil
555 }
556
557 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
558 it.pageInfo.MaxSize = int(req.GetPageSize())
559 it.pageInfo.Token = req.GetPageToken()
560
561 return it
562 }
563
564 // SendPackets send packets to the series.
565 //
566 // This method is not supported for the REST transport.
567 func (c *streamingRESTClient) SendPackets(ctx context.Context, opts ...gax.CallOption) (visionaipb.StreamingService_SendPacketsClient, error) {
568 return nil, errors.New("SendPackets not yet supported for REST clients")
569 }
570
571 // ReceivePackets receive packets from the series.
572 //
573 // This method is not supported for the REST transport.
574 func (c *streamingRESTClient) ReceivePackets(ctx context.Context, opts ...gax.CallOption) (visionaipb.StreamingService_ReceivePacketsClient, error) {
575 return nil, errors.New("ReceivePackets not yet supported for REST clients")
576 }
577
578 // ReceiveEvents receive events given the stream name.
579 //
580 // This method is not supported for the REST transport.
581 func (c *streamingRESTClient) ReceiveEvents(ctx context.Context, opts ...gax.CallOption) (visionaipb.StreamingService_ReceiveEventsClient, error) {
582 return nil, errors.New("ReceiveEvents not yet supported for REST clients")
583 }
584
585 // AcquireLease acquireLease acquires a lease.
586 func (c *streamingRESTClient) AcquireLease(ctx context.Context, req *visionaipb.AcquireLeaseRequest, opts ...gax.CallOption) (*visionaipb.Lease, error) {
587 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
588 jsonReq, err := m.Marshal(req)
589 if err != nil {
590 return nil, err
591 }
592
593 baseUrl, err := url.Parse(c.endpoint)
594 if err != nil {
595 return nil, err
596 }
597 baseUrl.Path += fmt.Sprintf("/v1/%v:acquireLease", req.GetSeries())
598
599 params := url.Values{}
600 params.Add("$alt", "json;enum-encoding=int")
601
602 baseUrl.RawQuery = params.Encode()
603
604 // Build HTTP headers from client and context metadata.
605 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "series", url.QueryEscape(req.GetSeries()))}
606
607 hds = append(c.xGoogHeaders, hds...)
608 hds = append(hds, "Content-Type", "application/json")
609 headers := gax.BuildHeaders(ctx, hds...)
610 opts = append((*c.CallOptions).AcquireLease[0:len((*c.CallOptions).AcquireLease):len((*c.CallOptions).AcquireLease)], opts...)
611 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
612 resp := &visionaipb.Lease{}
613 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
614 if settings.Path != "" {
615 baseUrl.Path = settings.Path
616 }
617 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
618 if err != nil {
619 return err
620 }
621 httpReq = httpReq.WithContext(ctx)
622 httpReq.Header = headers
623
624 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "AcquireLease")
625 if err != nil {
626 return err
627 }
628
629 if err := unm.Unmarshal(buf, resp); err != nil {
630 return err
631 }
632
633 return nil
634 }, opts...)
635 if e != nil {
636 return nil, e
637 }
638 return resp, nil
639 }
640
641 // RenewLease renewLease renews a lease.
642 func (c *streamingRESTClient) RenewLease(ctx context.Context, req *visionaipb.RenewLeaseRequest, opts ...gax.CallOption) (*visionaipb.Lease, error) {
643 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
644 jsonReq, err := m.Marshal(req)
645 if err != nil {
646 return nil, err
647 }
648
649 baseUrl, err := url.Parse(c.endpoint)
650 if err != nil {
651 return nil, err
652 }
653 baseUrl.Path += fmt.Sprintf("/v1/%v:renewLease", req.GetSeries())
654
655 params := url.Values{}
656 params.Add("$alt", "json;enum-encoding=int")
657
658 baseUrl.RawQuery = params.Encode()
659
660 // Build HTTP headers from client and context metadata.
661 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "series", url.QueryEscape(req.GetSeries()))}
662
663 hds = append(c.xGoogHeaders, hds...)
664 hds = append(hds, "Content-Type", "application/json")
665 headers := gax.BuildHeaders(ctx, hds...)
666 opts = append((*c.CallOptions).RenewLease[0:len((*c.CallOptions).RenewLease):len((*c.CallOptions).RenewLease)], opts...)
667 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
668 resp := &visionaipb.Lease{}
669 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
670 if settings.Path != "" {
671 baseUrl.Path = settings.Path
672 }
673 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
674 if err != nil {
675 return err
676 }
677 httpReq = httpReq.WithContext(ctx)
678 httpReq.Header = headers
679
680 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "RenewLease")
681 if err != nil {
682 return err
683 }
684
685 if err := unm.Unmarshal(buf, resp); err != nil {
686 return err
687 }
688
689 return nil
690 }, opts...)
691 if e != nil {
692 return nil, e
693 }
694 return resp, nil
695 }
696
697 // ReleaseLease rleaseLease releases a lease.
698 func (c *streamingRESTClient) ReleaseLease(ctx context.Context, req *visionaipb.ReleaseLeaseRequest, opts ...gax.CallOption) (*visionaipb.ReleaseLeaseResponse, error) {
699 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
700 jsonReq, err := m.Marshal(req)
701 if err != nil {
702 return nil, err
703 }
704
705 baseUrl, err := url.Parse(c.endpoint)
706 if err != nil {
707 return nil, err
708 }
709 baseUrl.Path += fmt.Sprintf("/v1/%v:releaseLease", req.GetSeries())
710
711 params := url.Values{}
712 params.Add("$alt", "json;enum-encoding=int")
713
714 baseUrl.RawQuery = params.Encode()
715
716 // Build HTTP headers from client and context metadata.
717 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "series", url.QueryEscape(req.GetSeries()))}
718
719 hds = append(c.xGoogHeaders, hds...)
720 hds = append(hds, "Content-Type", "application/json")
721 headers := gax.BuildHeaders(ctx, hds...)
722 opts = append((*c.CallOptions).ReleaseLease[0:len((*c.CallOptions).ReleaseLease):len((*c.CallOptions).ReleaseLease)], opts...)
723 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
724 resp := &visionaipb.ReleaseLeaseResponse{}
725 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
726 if settings.Path != "" {
727 baseUrl.Path = settings.Path
728 }
729 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
730 if err != nil {
731 return err
732 }
733 httpReq = httpReq.WithContext(ctx)
734 httpReq.Header = headers
735
736 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "ReleaseLease")
737 if err != nil {
738 return err
739 }
740
741 if err := unm.Unmarshal(buf, resp); err != nil {
742 return err
743 }
744
745 return nil
746 }, opts...)
747 if e != nil {
748 return nil, e
749 }
750 return resp, nil
751 }
752
753 // CancelOperation is a utility method from google.longrunning.Operations.
754 func (c *streamingRESTClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error {
755 m := protojson.MarshalOptions{AllowPartial: true, UseEnumNumbers: true}
756 jsonReq, err := m.Marshal(req)
757 if err != nil {
758 return err
759 }
760
761 baseUrl, err := url.Parse(c.endpoint)
762 if err != nil {
763 return err
764 }
765 baseUrl.Path += fmt.Sprintf("/v1/%v:cancel", req.GetName())
766
767 params := url.Values{}
768 params.Add("$alt", "json;enum-encoding=int")
769
770 baseUrl.RawQuery = params.Encode()
771
772 // Build HTTP headers from client and context metadata.
773 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
774
775 hds = append(c.xGoogHeaders, hds...)
776 hds = append(hds, "Content-Type", "application/json")
777 headers := gax.BuildHeaders(ctx, hds...)
778 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
779 if settings.Path != "" {
780 baseUrl.Path = settings.Path
781 }
782 httpReq, err := http.NewRequest("POST", baseUrl.String(), bytes.NewReader(jsonReq))
783 if err != nil {
784 return err
785 }
786 httpReq = httpReq.WithContext(ctx)
787 httpReq.Header = headers
788
789 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, jsonReq, "CancelOperation")
790 return err
791 }, opts...)
792 }
793
794 // DeleteOperation is a utility method from google.longrunning.Operations.
795 func (c *streamingRESTClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error {
796 baseUrl, err := url.Parse(c.endpoint)
797 if err != nil {
798 return err
799 }
800 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
801
802 params := url.Values{}
803 params.Add("$alt", "json;enum-encoding=int")
804
805 baseUrl.RawQuery = params.Encode()
806
807 // Build HTTP headers from client and context metadata.
808 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
809
810 hds = append(c.xGoogHeaders, hds...)
811 hds = append(hds, "Content-Type", "application/json")
812 headers := gax.BuildHeaders(ctx, hds...)
813 return gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
814 if settings.Path != "" {
815 baseUrl.Path = settings.Path
816 }
817 httpReq, err := http.NewRequest("DELETE", baseUrl.String(), nil)
818 if err != nil {
819 return err
820 }
821 httpReq = httpReq.WithContext(ctx)
822 httpReq.Header = headers
823
824 _, err = executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "DeleteOperation")
825 return err
826 }, opts...)
827 }
828
829 // GetOperation is a utility method from google.longrunning.Operations.
830 func (c *streamingRESTClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error) {
831 baseUrl, err := url.Parse(c.endpoint)
832 if err != nil {
833 return nil, err
834 }
835 baseUrl.Path += fmt.Sprintf("/v1/%v", req.GetName())
836
837 params := url.Values{}
838 params.Add("$alt", "json;enum-encoding=int")
839
840 baseUrl.RawQuery = params.Encode()
841
842 // Build HTTP headers from client and context metadata.
843 hds := []string{"x-goog-request-params", fmt.Sprintf("%s=%v", "name", url.QueryEscape(req.GetName()))}
844
845 hds = append(c.xGoogHeaders, hds...)
846 hds = append(hds, "Content-Type", "application/json")
847 headers := gax.BuildHeaders(ctx, hds...)
848 opts = append((*c.CallOptions).GetOperation[0:len((*c.CallOptions).GetOperation):len((*c.CallOptions).GetOperation)], opts...)
849 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
850 resp := &longrunningpb.Operation{}
851 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
852 if settings.Path != "" {
853 baseUrl.Path = settings.Path
854 }
855 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
856 if err != nil {
857 return err
858 }
859 httpReq = httpReq.WithContext(ctx)
860 httpReq.Header = headers
861
862 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "GetOperation")
863 if err != nil {
864 return err
865 }
866
867 if err := unm.Unmarshal(buf, resp); err != nil {
868 return err
869 }
870
871 return nil
872 }, opts...)
873 if e != nil {
874 return nil, e
875 }
876 return resp, nil
877 }
878
879 // ListOperations is a utility method from google.longrunning.Operations.
880 func (c *streamingRESTClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator {
881 it := &OperationIterator{}
882 req = proto.Clone(req).(*longrunningpb.ListOperationsRequest)
883 unm := protojson.UnmarshalOptions{AllowPartial: true, DiscardUnknown: true}
884 it.InternalFetch = func(pageSize int, pageToken string) ([]*longrunningpb.Operation, string, error) {
885 resp := &longrunningpb.ListOperationsResponse{}
886 if pageToken != "" {
887 req.PageToken = pageToken
888 }
889 if pageSize > math.MaxInt32 {
890 req.PageSize = math.MaxInt32
891 } else if pageSize != 0 {
892 req.PageSize = int32(pageSize)
893 }
894 baseUrl, err := url.Parse(c.endpoint)
895 if err != nil {
896 return nil, "", err
897 }
898 baseUrl.Path += fmt.Sprintf("/v1/%v/operations", req.GetName())
899
900 params := url.Values{}
901 params.Add("$alt", "json;enum-encoding=int")
902 if req.GetFilter() != "" {
903 params.Add("filter", fmt.Sprintf("%v", req.GetFilter()))
904 }
905 if req.GetPageSize() != 0 {
906 params.Add("pageSize", fmt.Sprintf("%v", req.GetPageSize()))
907 }
908 if req.GetPageToken() != "" {
909 params.Add("pageToken", fmt.Sprintf("%v", req.GetPageToken()))
910 }
911
912 baseUrl.RawQuery = params.Encode()
913
914 // Build HTTP headers from client and context metadata.
915 hds := append(c.xGoogHeaders, "Content-Type", "application/json")
916 headers := gax.BuildHeaders(ctx, hds...)
917 e := gax.Invoke(ctx, func(ctx context.Context, settings gax.CallSettings) error {
918 if settings.Path != "" {
919 baseUrl.Path = settings.Path
920 }
921 httpReq, err := http.NewRequest("GET", baseUrl.String(), nil)
922 if err != nil {
923 return err
924 }
925 httpReq.Header = headers
926
927 buf, err := executeHTTPRequest(ctx, c.httpClient, httpReq, c.logger, nil, "ListOperations")
928 if err != nil {
929 return err
930 }
931 if err := unm.Unmarshal(buf, resp); err != nil {
932 return err
933 }
934
935 return nil
936 }, opts...)
937 if e != nil {
938 return nil, "", e
939 }
940 it.Response = resp
941 return resp.GetOperations(), resp.GetNextPageToken(), nil
942 }
943
944 fetch := func(pageSize int, pageToken string) (string, error) {
945 items, nextPageToken, err := it.InternalFetch(pageSize, pageToken)
946 if err != nil {
947 return "", err
948 }
949 it.items = append(it.items, items...)
950 return nextPageToken, nil
951 }
952
953 it.pageInfo, it.nextFunc = iterator.NewPageInfo(fetch, it.bufLen, it.takeBuf)
954 it.pageInfo.MaxSize = int(req.GetPageSize())
955 it.pageInfo.Token = req.GetPageToken()
956
957 return it
958 }