1// Protocol Buffers - Google's data interchange format 2// Copyright 2008 Google Inc. All rights reserved. 3// https://developers.google.com/protocol-buffers/ 4// 5// Redistribution and use in source and binary forms, with or without 6// modification, are permitted provided that the following conditions are 7// met: 8// 9// * Redistributions of source code must retain the above copyright 10// notice, this list of conditions and the following disclaimer. 11// * Redistributions in binary form must reproduce the above 12// copyright notice, this list of conditions and the following disclaimer 13// in the documentation and/or other materials provided with the 14// distribution. 15// * Neither the name of Google Inc. nor the names of its 16// contributors may be used to endorse or promote products derived from 17// this software without specific prior written permission. 18// 19// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 31// Code generated by protoc-gen-go. DO NOT EDIT. 32// source: google/protobuf/duration.proto 33 34// Package durationpb contains generated types for google/protobuf/duration.proto. 35// 36// The Duration message represents a signed span of time. 37// 38// # Conversion to a Go Duration 39// 40// The AsDuration method can be used to convert a Duration message to a 41// standard Go time.Duration value: 42// 43// d := dur.AsDuration() 44// ... // make use of d as a time.Duration 45// 46// Converting to a time.Duration is a common operation so that the extensive 47// set of time-based operations provided by the time package can be leveraged. 48// See https://golang.org/pkg/time for more information. 49// 50// The AsDuration method performs the conversion on a best-effort basis. 51// Durations with denormal values (e.g., nanoseconds beyond -99999999 and 52// +99999999, inclusive; or seconds and nanoseconds with opposite signs) 53// are normalized during the conversion to a time.Duration. To manually check for 54// invalid Duration per the documented limitations in duration.proto, 55// additionally call the CheckValid method: 56// 57// if err := dur.CheckValid(); err != nil { 58// ... // handle error 59// } 60// 61// Note that the documented limitations in duration.proto does not protect a 62// Duration from overflowing the representable range of a time.Duration in Go. 63// The AsDuration method uses saturation arithmetic such that an overflow clamps 64// the resulting value to the closest representable value (e.g., math.MaxInt64 65// for positive overflow and math.MinInt64 for negative overflow). 66// 67// # Conversion from a Go Duration 68// 69// The durationpb.New function can be used to construct a Duration message 70// from a standard Go time.Duration value: 71// 72// dur := durationpb.New(d) 73// ... // make use of d as a *durationpb.Duration 74package durationpb 75 76import ( 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// A Duration represents a signed, fixed-length span of time represented 86// as a count of seconds and fractions of seconds at nanosecond 87// resolution. It is independent of any calendar and concepts like "day" 88// or "month". It is related to Timestamp in that the difference between 89// two Timestamp values is a Duration and it can be added or subtracted 90// from a Timestamp. Range is approximately +-10,000 years. 91// 92// # Examples 93// 94// Example 1: Compute Duration from two Timestamps in pseudo code. 95// 96// Timestamp start = ...; 97// Timestamp end = ...; 98// Duration duration = ...; 99// 100// duration.seconds = end.seconds - start.seconds; 101// duration.nanos = end.nanos - start.nanos; 102// 103// if (duration.seconds < 0 && duration.nanos > 0) { 104// duration.seconds += 1; 105// duration.nanos -= 1000000000; 106// } else if (duration.seconds > 0 && duration.nanos < 0) { 107// duration.seconds -= 1; 108// duration.nanos += 1000000000; 109// } 110// 111// Example 2: Compute Timestamp from Timestamp + Duration in pseudo code. 112// 113// Timestamp start = ...; 114// Duration duration = ...; 115// Timestamp end = ...; 116// 117// end.seconds = start.seconds + duration.seconds; 118// end.nanos = start.nanos + duration.nanos; 119// 120// if (end.nanos < 0) { 121// end.seconds -= 1; 122// end.nanos += 1000000000; 123// } else if (end.nanos >= 1000000000) { 124// end.seconds += 1; 125// end.nanos -= 1000000000; 126// } 127// 128// Example 3: Compute Duration from datetime.timedelta in Python. 129// 130// td = datetime.timedelta(days=3, minutes=10) 131// duration = Duration() 132// duration.FromTimedelta(td) 133// 134// # JSON Mapping 135// 136// In JSON format, the Duration type is encoded as a string rather than an 137// object, where the string ends in the suffix "s" (indicating seconds) and 138// is preceded by the number of seconds, with nanoseconds expressed as 139// fractional seconds. For example, 3 seconds with 0 nanoseconds should be 140// encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should 141// be expressed in JSON format as "3.000000001s", and 3 seconds and 1 142// microsecond should be expressed in JSON format as "3.000001s". 143type Duration struct { 144 state protoimpl.MessageState 145 sizeCache protoimpl.SizeCache 146 unknownFields protoimpl.UnknownFields 147 148 // Signed seconds of the span of time. Must be from -315,576,000,000 149 // to +315,576,000,000 inclusive. Note: these bounds are computed from: 150 // 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years 151 Seconds int64 `protobuf:"varint,1,opt,name=seconds,proto3" json:"seconds,omitempty"` 152 // Signed fractions of a second at nanosecond resolution of the span 153 // of time. Durations less than one second are represented with a 0 154 // `seconds` field and a positive or negative `nanos` field. For durations 155 // of one second or more, a non-zero value for the `nanos` field must be 156 // of the same sign as the `seconds` field. Must be from -999,999,999 157 // to +999,999,999 inclusive. 158 Nanos int32 `protobuf:"varint,2,opt,name=nanos,proto3" json:"nanos,omitempty"` 159} 160 161// New constructs a new Duration from the provided time.Duration. 162func 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// AsDuration converts x to a time.Duration, 170// returning the closest duration value in the event of overflow. 171func (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// IsValid reports whether the duration is valid. 191// It is equivalent to CheckValid == nil. 192func (x *Duration) IsValid() bool { 193 return x.check() == 0 194} 195 196// CheckValid returns an error if the duration is invalid. 197// In particular, it checks whether the value is within the range of 198// -10000 years to +10000 years inclusive. 199// An error is reported for a nil Duration. 200func (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 217const ( 218 _ = iota 219 invalidNil 220 invalidUnderflow 221 invalidOverflow 222 invalidNanosRange 223 invalidNanosSign 224) 225 226func (x *Duration) check() uint { 227 const absDuration = 315576000000 // 10000yr * 365.25day/yr * 24hr/day * 60min/hr * 60sec/min 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 246func (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 255func (x *Duration) String() string { 256 return protoimpl.X.MessageStringOf(x) 257} 258 259func (*Duration) ProtoMessage() {} 260 261func (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// Deprecated: Use Duration.ProtoReflect.Descriptor instead. 274func (*Duration) Descriptor() ([]byte, []int) { 275 return file_google_protobuf_duration_proto_rawDescGZIP(), []int{0} 276} 277 278func (x *Duration) GetSeconds() int64 { 279 if x != nil { 280 return x.Seconds 281 } 282 return 0 283} 284 285func (x *Duration) GetNanos() int32 { 286 if x != nil { 287 return x.Nanos 288 } 289 return 0 290} 291 292var File_google_protobuf_duration_proto protoreflect.FileDescriptor 293 294var 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 313var ( 314 file_google_protobuf_duration_proto_rawDescOnce sync.Once 315 file_google_protobuf_duration_proto_rawDescData = file_google_protobuf_duration_proto_rawDesc 316) 317 318func 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 325var file_google_protobuf_duration_proto_msgTypes = make([]protoimpl.MessageInfo, 1) 326var file_google_protobuf_duration_proto_goTypes = []interface{}{ 327 (*Duration)(nil), // 0: google.protobuf.Duration 328} 329var file_google_protobuf_duration_proto_depIdxs = []int32{ 330 0, // [0:0] is the sub-list for method output_type 331 0, // [0:0] is the sub-list for method input_type 332 0, // [0:0] is the sub-list for extension type_name 333 0, // [0:0] is the sub-list for extension extendee 334 0, // [0:0] is the sub-list for field type_name 335} 336 337func init() { file_google_protobuf_duration_proto_init() } 338func 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