duration.pb.swift 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // DO NOT EDIT.
  2. // swift-format-ignore-file
  3. // swiftlint:disable all
  4. //
  5. // Generated by the Swift generator plugin for the protocol buffer compiler.
  6. // Source: google/protobuf/duration.proto
  7. //
  8. // For information on using the generated types, please see the documentation:
  9. // https://github.com/apple/swift-protobuf/
  10. // Protocol Buffers - Google's data interchange format
  11. // Copyright 2008 Google Inc. All rights reserved.
  12. // https://developers.google.com/protocol-buffers/
  13. //
  14. // Redistribution and use in source and binary forms, with or without
  15. // modification, are permitted provided that the following conditions are
  16. // met:
  17. //
  18. // * Redistributions of source code must retain the above copyright
  19. // notice, this list of conditions and the following disclaimer.
  20. // * Redistributions in binary form must reproduce the above
  21. // copyright notice, this list of conditions and the following disclaimer
  22. // in the documentation and/or other materials provided with the
  23. // distribution.
  24. // * Neither the name of Google Inc. nor the names of its
  25. // contributors may be used to endorse or promote products derived from
  26. // this software without specific prior written permission.
  27. //
  28. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  29. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  30. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  31. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  32. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  33. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  34. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  35. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  36. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  37. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  38. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  39. // 'import SwiftProtobuf' suppressed, this proto file is meant to be bundled in the runtime.
  40. // If the compiler emits an error on this type, it is because this file
  41. // was generated by a version of the `protoc` Swift plug-in that is
  42. // incompatible with the version of SwiftProtobuf to which you are linking.
  43. // Please ensure that you are building against the same version of the API
  44. // that was used to generate this file.
  45. fileprivate struct _GeneratedWithProtocGenSwiftVersion: ProtobufAPIVersionCheck {
  46. struct _2: ProtobufAPIVersion_2 {}
  47. typealias Version = _2
  48. }
  49. /// A Duration represents a signed, fixed-length span of time represented
  50. /// as a count of seconds and fractions of seconds at nanosecond
  51. /// resolution. It is independent of any calendar and concepts like "day"
  52. /// or "month". It is related to Timestamp in that the difference between
  53. /// two Timestamp values is a Duration and it can be added or subtracted
  54. /// from a Timestamp. Range is approximately +-10,000 years.
  55. ///
  56. /// # Examples
  57. ///
  58. /// Example 1: Compute Duration from two Timestamps in pseudo code.
  59. ///
  60. /// Timestamp start = ...;
  61. /// Timestamp end = ...;
  62. /// Duration duration = ...;
  63. ///
  64. /// duration.seconds = end.seconds - start.seconds;
  65. /// duration.nanos = end.nanos - start.nanos;
  66. ///
  67. /// if (duration.seconds < 0 && duration.nanos > 0) {
  68. /// duration.seconds += 1;
  69. /// duration.nanos -= 1000000000;
  70. /// } else if (duration.seconds > 0 && duration.nanos < 0) {
  71. /// duration.seconds -= 1;
  72. /// duration.nanos += 1000000000;
  73. /// }
  74. ///
  75. /// Example 2: Compute Timestamp from Timestamp + Duration in pseudo code.
  76. ///
  77. /// Timestamp start = ...;
  78. /// Duration duration = ...;
  79. /// Timestamp end = ...;
  80. ///
  81. /// end.seconds = start.seconds + duration.seconds;
  82. /// end.nanos = start.nanos + duration.nanos;
  83. ///
  84. /// if (end.nanos < 0) {
  85. /// end.seconds -= 1;
  86. /// end.nanos += 1000000000;
  87. /// } else if (end.nanos >= 1000000000) {
  88. /// end.seconds += 1;
  89. /// end.nanos -= 1000000000;
  90. /// }
  91. ///
  92. /// Example 3: Compute Duration from datetime.timedelta in Python.
  93. ///
  94. /// td = datetime.timedelta(days=3, minutes=10)
  95. /// duration = Duration()
  96. /// duration.FromTimedelta(td)
  97. ///
  98. /// # JSON Mapping
  99. ///
  100. /// In JSON format, the Duration type is encoded as a string rather than an
  101. /// object, where the string ends in the suffix "s" (indicating seconds) and
  102. /// is preceded by the number of seconds, with nanoseconds expressed as
  103. /// fractional seconds. For example, 3 seconds with 0 nanoseconds should be
  104. /// encoded in JSON format as "3s", while 3 seconds and 1 nanosecond should
  105. /// be expressed in JSON format as "3.000000001s", and 3 seconds and 1
  106. /// microsecond should be expressed in JSON format as "3.000001s".
  107. public struct Google_Protobuf_Duration: Sendable {
  108. // SwiftProtobuf.Message conformance is added in an extension below. See the
  109. // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
  110. // methods supported on all messages.
  111. /// Signed seconds of the span of time. Must be from -315,576,000,000
  112. /// to +315,576,000,000 inclusive. Note: these bounds are computed from:
  113. /// 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
  114. public var seconds: Int64 = 0
  115. /// Signed fractions of a second at nanosecond resolution of the span
  116. /// of time. Durations less than one second are represented with a 0
  117. /// `seconds` field and a positive or negative `nanos` field. For durations
  118. /// of one second or more, a non-zero value for the `nanos` field must be
  119. /// of the same sign as the `seconds` field. Must be from -999,999,999
  120. /// to +999,999,999 inclusive.
  121. public var nanos: Int32 = 0
  122. public var unknownFields = UnknownStorage()
  123. public init() {}
  124. }
  125. // MARK: - Code below here is support for the SwiftProtobuf runtime.
  126. fileprivate let _protobuf_package = "google.protobuf"
  127. extension Google_Protobuf_Duration: Message, _MessageImplementationBase, _ProtoNameProviding {
  128. public static let protoMessageName: String = _protobuf_package + ".Duration"
  129. public static let _protobuf_nameMap = _NameMap(bytecode: "\0\u{1}seconds\0\u{1}nanos\0")
  130. public mutating func decodeMessage<D: Decoder>(decoder: inout D) throws {
  131. while let fieldNumber = try decoder.nextFieldNumber() {
  132. // The use of inline closures is to circumvent an issue where the compiler
  133. // allocates stack space for every case branch when no optimizations are
  134. // enabled. https://github.com/apple/swift-protobuf/issues/1034
  135. switch fieldNumber {
  136. case 1: try { try decoder.decodeSingularInt64Field(value: &self.seconds) }()
  137. case 2: try { try decoder.decodeSingularInt32Field(value: &self.nanos) }()
  138. default: break
  139. }
  140. }
  141. }
  142. public func traverse<V: Visitor>(visitor: inout V) throws {
  143. if self.seconds != 0 {
  144. try visitor.visitSingularInt64Field(value: self.seconds, fieldNumber: 1)
  145. }
  146. if self.nanos != 0 {
  147. try visitor.visitSingularInt32Field(value: self.nanos, fieldNumber: 2)
  148. }
  149. try unknownFields.traverse(visitor: &visitor)
  150. }
  151. public static func ==(lhs: Google_Protobuf_Duration, rhs: Google_Protobuf_Duration) -> Bool {
  152. if lhs.seconds != rhs.seconds {return false}
  153. if lhs.nanos != rhs.nanos {return false}
  154. if lhs.unknownFields != rhs.unknownFields {return false}
  155. return true
  156. }
  157. }