1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 package durationpb
75
76 import (
77 protoreflect "google.golang.org/protobuf/reflect/protoreflect"
78 protoimpl "google.golang.org/protobuf/runtime/protoimpl"
79 math "math"
80 reflect "reflect"
81 sync "sync"
82 time "time"
83 )
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143 type Duration struct {
144 state protoimpl.MessageState
145 sizeCache protoimpl.SizeCache
146 unknownFields protoimpl.UnknownFields
147
148
149
150
151 Seconds int64 `protobuf:"varint,1,opt,name=seconds,proto3" json:"seconds,omitempty"`
152
153
154
155
156
157
158 Nanos int32 `protobuf:"varint,2,opt,name=nanos,proto3" json:"nanos,omitempty"`
159 }
160
161
162 func New(d time.Duration) *Duration {
163 nanos := d.Nanoseconds()
164 secs := nanos / 1e9
165 nanos -= secs * 1e9
166 return &Duration{Seconds: int64(secs), Nanos: int32(nanos)}
167 }
168
169
170
171 func (x *Duration) AsDuration() time.Duration {
172 secs := x.GetSeconds()
173 nanos := x.GetNanos()
174 d := time.Duration(secs) * time.Second
175 overflow := d/time.Second != time.Duration(secs)
176 d += time.Duration(nanos) * time.Nanosecond
177 overflow = overflow || (secs < 0 && nanos < 0 && d > 0)
178 overflow = overflow || (secs > 0 && nanos > 0 && d < 0)
179 if overflow {
180 switch {
181 case secs < 0:
182 return time.Duration(math.MinInt64)
183 case secs > 0:
184 return time.Duration(math.MaxInt64)
185 }
186 }
187 return d
188 }
189
190
191
192 func (x *Duration) IsValid() bool {
193 return x.check() == 0
194 }
195
196
197
198
199
200 func (x *Duration) CheckValid() error {
201 switch x.check() {
202 case invalidNil:
203 return protoimpl.X.NewError("invalid nil Duration")
204 case invalidUnderflow:
205 return protoimpl.X.NewError("duration (%v) exceeds -10000 years", x)
206 case invalidOverflow:
207 return protoimpl.X.NewError("duration (%v) exceeds +10000 years", x)
208 case invalidNanosRange:
209 return protoimpl.X.NewError("duration (%v) has out-of-range nanos", x)
210 case invalidNanosSign:
211 return protoimpl.X.NewError("duration (%v) has seconds and nanos with different signs", x)
212 default:
213 return nil
214 }
215 }
216
217 const (
218 _ = iota
219 invalidNil
220 invalidUnderflow
221 invalidOverflow
222 invalidNanosRange
223 invalidNanosSign
224 )
225
226 func (x *Duration) check() uint {
227 const absDuration = 315576000000
228 secs := x.GetSeconds()
229 nanos := x.GetNanos()
230 switch {
231 case x == nil:
232 return invalidNil
233 case secs < -absDuration:
234 return invalidUnderflow
235 case secs > +absDuration:
236 return invalidOverflow
237 case nanos <= -1e9 || nanos >= +1e9:
238 return invalidNanosRange
239 case (secs > 0 && nanos < 0) || (secs < 0 && nanos > 0):
240 return invalidNanosSign
241 default:
242 return 0
243 }
244 }
245
246 func (x *Duration) Reset() {
247 *x = Duration{}
248 if protoimpl.UnsafeEnabled {
249 mi := &file_google_protobuf_duration_proto_msgTypes[0]
250 ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
251 ms.StoreMessageInfo(mi)
252 }
253 }
254
255 func (x *Duration) String() string {
256 return protoimpl.X.MessageStringOf(x)
257 }
258
259 func (*Duration) ProtoMessage() {}
260
261 func (x *Duration) ProtoReflect() protoreflect.Message {
262 mi := &file_google_protobuf_duration_proto_msgTypes[0]
263 if protoimpl.UnsafeEnabled && x != nil {
264 ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
265 if ms.LoadMessageInfo() == nil {
266 ms.StoreMessageInfo(mi)
267 }
268 return ms
269 }
270 return mi.MessageOf(x)
271 }
272
273
274 func (*Duration) Descriptor() ([]byte, []int) {
275 return file_google_protobuf_duration_proto_rawDescGZIP(), []int{0}
276 }
277
278 func (x *Duration) GetSeconds() int64 {
279 if x != nil {
280 return x.Seconds
281 }
282 return 0
283 }
284
285 func (x *Duration) GetNanos() int32 {
286 if x != nil {
287 return x.Nanos
288 }
289 return 0
290 }
291
292 var File_google_protobuf_duration_proto protoreflect.FileDescriptor
293
294 var file_google_protobuf_duration_proto_rawDesc = []byte{
295 0x0a, 0x1e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75,
296 0x66, 0x2f, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
297 0x12, 0x0f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75,
298 0x66, 0x22, 0x3a, 0x0a, 0x08, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x0a,
299 0x07, 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x07,
300 0x73, 0x65, 0x63, 0x6f, 0x6e, 0x64, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x6e, 0x61, 0x6e, 0x6f, 0x73,
301 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x6e, 0x61, 0x6e, 0x6f, 0x73, 0x42, 0x83, 0x01,
302 0x0a, 0x13, 0x63, 0x6f, 0x6d, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f,
303 0x74, 0x6f, 0x62, 0x75, 0x66, 0x42, 0x0d, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x50,
304 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x31, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x67,
305 0x6f, 0x6c, 0x61, 0x6e, 0x67, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62,
306 0x75, 0x66, 0x2f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x2f, 0x64,
307 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x70, 0x62, 0xf8, 0x01, 0x01, 0xa2, 0x02, 0x03, 0x47,
308 0x50, 0x42, 0xaa, 0x02, 0x1e, 0x47, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x50, 0x72, 0x6f, 0x74,
309 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x57, 0x65, 0x6c, 0x6c, 0x4b, 0x6e, 0x6f, 0x77, 0x6e, 0x54, 0x79,
310 0x70, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
311 }
312
313 var (
314 file_google_protobuf_duration_proto_rawDescOnce sync.Once
315 file_google_protobuf_duration_proto_rawDescData = file_google_protobuf_duration_proto_rawDesc
316 )
317
318 func file_google_protobuf_duration_proto_rawDescGZIP() []byte {
319 file_google_protobuf_duration_proto_rawDescOnce.Do(func() {
320 file_google_protobuf_duration_proto_rawDescData = protoimpl.X.CompressGZIP(file_google_protobuf_duration_proto_rawDescData)
321 })
322 return file_google_protobuf_duration_proto_rawDescData
323 }
324
325 var file_google_protobuf_duration_proto_msgTypes = make([]protoimpl.MessageInfo, 1)
326 var file_google_protobuf_duration_proto_goTypes = []interface{}{
327 (*Duration)(nil),
328 }
329 var file_google_protobuf_duration_proto_depIdxs = []int32{
330 0,
331 0,
332 0,
333 0,
334 0,
335 }
336
337 func init() { file_google_protobuf_duration_proto_init() }
338 func file_google_protobuf_duration_proto_init() {
339 if File_google_protobuf_duration_proto != nil {
340 return
341 }
342 if !protoimpl.UnsafeEnabled {
343 file_google_protobuf_duration_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
344 switch v := v.(*Duration); i {
345 case 0:
346 return &v.state
347 case 1:
348 return &v.sizeCache
349 case 2:
350 return &v.unknownFields
351 default:
352 return nil
353 }
354 }
355 }
356 type x struct{}
357 out := protoimpl.TypeBuilder{
358 File: protoimpl.DescBuilder{
359 GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
360 RawDescriptor: file_google_protobuf_duration_proto_rawDesc,
361 NumEnums: 0,
362 NumMessages: 1,
363 NumExtensions: 0,
364 NumServices: 0,
365 },
366 GoTypes: file_google_protobuf_duration_proto_goTypes,
367 DependencyIndexes: file_google_protobuf_duration_proto_depIdxs,
368 MessageInfos: file_google_protobuf_duration_proto_msgTypes,
369 }.Build()
370 File_google_protobuf_duration_proto = out.File
371 file_google_protobuf_duration_proto_rawDesc = nil
372 file_google_protobuf_duration_proto_goTypes = nil
373 file_google_protobuf_duration_proto_depIdxs = nil
374 }
375
View as plain text