Debian Codegraph @

speech/apiv1p1beta1/auxiliary.go

raw symbols SCIP
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 speech
18
19 import (
20 "context"
21 "time"
22
23 "cloud.google.com/go/longrunning"
24 longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
25 speechpb "cloud.google.com/go/speech/apiv1p1beta1/speechpb"
26 gax "github.com/googleapis/gax-go/v2"
27 "google.golang.org/api/iterator"
28 )
29
30 // LongRunningRecognizeOperation manages a long-running operation from LongRunningRecognize.
31 type LongRunningRecognizeOperation struct {
32 lro *longrunning.Operation
33 pollPath string
34 }
35
36 // Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
37 //
38 // See documentation of Poll for error-handling information.
39 func (op *LongRunningRecognizeOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*speechpb.LongRunningRecognizeResponse, error) {
40 opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...)
41 var resp speechpb.LongRunningRecognizeResponse
42 if err := op.lro.WaitWithInterval(ctx, &resp, time.Minute, opts...); err != nil {
43 return nil, err
44 }
45 return &resp, nil
46 }
47
48 // Poll fetches the latest state of the long-running operation.
49 //
50 // Poll also fetches the latest metadata, which can be retrieved by Metadata.
51 //
52 // If Poll fails, the error is returned and op is unmodified. If Poll succeeds and
53 // the operation has completed with failure, the error is returned and op.Done will return true.
54 // If Poll succeeds and the operation has completed successfully,
55 // op.Done will return true, and the response of the operation is returned.
56 // If Poll succeeds and the operation has not completed, the returned response and error are both nil.
57 func (op *LongRunningRecognizeOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*speechpb.LongRunningRecognizeResponse, error) {
58 opts = append([]gax.CallOption{gax.WithPath(op.pollPath)}, opts...)
59 var resp speechpb.LongRunningRecognizeResponse
60 if err := op.lro.Poll(ctx, &resp, opts...); err != nil {
61 return nil, err
62 }
63 if !op.Done() {
64 return nil, nil
65 }
66 return &resp, nil
67 }
68
69 // Metadata returns metadata associated with the long-running operation.
70 // Metadata itself does not contact the server, but Poll does.
71 // To get the latest metadata, call this method after a successful call to Poll.
72 // If the metadata is not available, the returned metadata and error are both nil.
73 func (op *LongRunningRecognizeOperation) Metadata() (*speechpb.LongRunningRecognizeMetadata, error) {
74 var meta speechpb.LongRunningRecognizeMetadata
75 if err := op.lro.Metadata(&meta); err == longrunning.ErrNoMetadata {
76 return nil, nil
77 } else if err != nil {
78 return nil, err
79 }
80 return &meta, nil
81 }
82
83 // Done reports whether the long-running operation has completed.
84 func (op *LongRunningRecognizeOperation) Done() bool {
85 return op.lro.Done()
86 }
87
88 // Name returns the name of the long-running operation.
89 // The name is assigned by the server and is unique within the service from which the operation is created.
90 func (op *LongRunningRecognizeOperation) Name() string {
91 return op.lro.Name()
92 }
93
94 // CustomClassIterator manages a stream of *speechpb.CustomClass.
95 type CustomClassIterator struct {
96 items []*speechpb.CustomClass
97 pageInfo *iterator.PageInfo
98 nextFunc func() error
99
100 // Response is the raw response for the current page.
101 // It must be cast to the RPC response type.
102 // Calling Next() or InternalFetch() updates this value.
103 Response interface{}
104
105 // InternalFetch is for use by the Google Cloud Libraries only.
106 // It is not part of the stable interface of this package.
107 //
108 // InternalFetch returns results from a single call to the underlying RPC.
109 // The number of results is no greater than pageSize.
110 // If there are no more results, nextPageToken is empty and err is nil.
111 InternalFetch func(pageSize int, pageToken string) (results []*speechpb.CustomClass, nextPageToken string, err error)
112 }
113
114 // PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
115 func (it *CustomClassIterator) PageInfo() *iterator.PageInfo {
116 return it.pageInfo
117 }
118
119 // Next returns the next result. Its second return value is iterator.Done if there are no more
120 // results. Once Next returns Done, all subsequent calls will return Done.
121 func (it *CustomClassIterator) Next() (*speechpb.CustomClass, error) {
122 var item *speechpb.CustomClass
123 if err := it.nextFunc(); err != nil {
124 return item, err
125 }
126 item = it.items[0]
127 it.items = it.items[1:]
128 return item, nil
129 }
130
131 func (it *CustomClassIterator) bufLen() int {
132 return len(it.items)
133 }
134
135 func (it *CustomClassIterator) takeBuf() interface{} {
136 b := it.items
137 it.items = nil
138 return b
139 }
140
141 // OperationIterator manages a stream of *longrunningpb.Operation.
142 type OperationIterator struct {
143 items []*longrunningpb.Operation
144 pageInfo *iterator.PageInfo
145 nextFunc func() error
146
147 // Response is the raw response for the current page.
148 // It must be cast to the RPC response type.
149 // Calling Next() or InternalFetch() updates this value.
150 Response interface{}
151
152 // InternalFetch is for use by the Google Cloud Libraries only.
153 // It is not part of the stable interface of this package.
154 //
155 // InternalFetch returns results from a single call to the underlying RPC.
156 // The number of results is no greater than pageSize.
157 // If there are no more results, nextPageToken is empty and err is nil.
158 InternalFetch func(pageSize int, pageToken string) (results []*longrunningpb.Operation, nextPageToken string, err error)
159 }
160
161 // PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
162 func (it *OperationIterator) PageInfo() *iterator.PageInfo {
163 return it.pageInfo
164 }
165
166 // Next returns the next result. Its second return value is iterator.Done if there are no more
167 // results. Once Next returns Done, all subsequent calls will return Done.
168 func (it *OperationIterator) Next() (*longrunningpb.Operation, error) {
169 var item *longrunningpb.Operation
170 if err := it.nextFunc(); err != nil {
171 return item, err
172 }
173 item = it.items[0]
174 it.items = it.items[1:]
175 return item, nil
176 }
177
178 func (it *OperationIterator) bufLen() int {
179 return len(it.items)
180 }
181
182 func (it *OperationIterator) takeBuf() interface{} {
183 b := it.items
184 it.items = nil
185 return b
186 }
187
188 // PhraseSetIterator manages a stream of *speechpb.PhraseSet.
189 type PhraseSetIterator struct {
190 items []*speechpb.PhraseSet
191 pageInfo *iterator.PageInfo
192 nextFunc func() error
193
194 // Response is the raw response for the current page.
195 // It must be cast to the RPC response type.
196 // Calling Next() or InternalFetch() updates this value.
197 Response interface{}
198
199 // InternalFetch is for use by the Google Cloud Libraries only.
200 // It is not part of the stable interface of this package.
201 //
202 // InternalFetch returns results from a single call to the underlying RPC.
203 // The number of results is no greater than pageSize.
204 // If there are no more results, nextPageToken is empty and err is nil.
205 InternalFetch func(pageSize int, pageToken string) (results []*speechpb.PhraseSet, nextPageToken string, err error)
206 }
207
208 // PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
209 func (it *PhraseSetIterator) PageInfo() *iterator.PageInfo {
210 return it.pageInfo
211 }
212
213 // Next returns the next result. Its second return value is iterator.Done if there are no more
214 // results. Once Next returns Done, all subsequent calls will return Done.
215 func (it *PhraseSetIterator) Next() (*speechpb.PhraseSet, error) {
216 var item *speechpb.PhraseSet
217 if err := it.nextFunc(); err != nil {
218 return item, err
219 }
220 item = it.items[0]
221 it.items = it.items[1:]
222 return item, nil
223 }
224
225 func (it *PhraseSetIterator) bufLen() int {
226 return len(it.items)
227 }
228
229 func (it *PhraseSetIterator) takeBuf() interface{} {
230 b := it.items
231 it.items = nil
232 return b
233 }