unittest_swift_oneof_merging.pb.swift 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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: unittest_swift_oneof_merging.proto
  7. //
  8. // For information on using the generated types, please see the documentation:
  9. // https://github.com/apple/swift-protobuf/
  10. // Protos/unittest_swift_oneof_merging.proto - test proto
  11. //
  12. // This source file is part of the Swift.org open source project
  13. //
  14. // Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
  15. // Licensed under Apache License v2.0 with Runtime Library Exception
  16. //
  17. // See http://swift.org/LICENSE.txt for license information
  18. // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
  19. //
  20. // -----------------------------------------------------------------------------
  21. ///
  22. /// This is based on unittest.proto's TestParsingMerge & RepeatedFieldsGenerator,
  23. /// but focused on oneofs to ensure the behaviors around merging/replaces on
  24. /// oneofs is correct.
  25. ///
  26. // -----------------------------------------------------------------------------
  27. import Foundation
  28. import SwiftProtobuf
  29. // If the compiler emits an error on this type, it is because this file
  30. // was generated by a version of the `protoc` Swift plug-in that is
  31. // incompatible with the version of SwiftProtobuf to which you are linking.
  32. // Please ensure that you are building against the same version of the API
  33. // that was used to generate this file.
  34. fileprivate struct _GeneratedWithProtocGenSwiftVersion: SwiftProtobuf.ProtobufAPIVersionCheck {
  35. struct _2: SwiftProtobuf.ProtobufAPIVersion_2 {}
  36. typealias Version = _2
  37. }
  38. struct SwiftProtoTesting_Merging_TestMessage: Sendable {
  39. // SwiftProtobuf.Message conformance is added in an extension below. See the
  40. // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
  41. // methods supported on all messages.
  42. var oneofField: SwiftProtoTesting_Merging_TestMessage.OneOf_OneofField? = nil
  43. var oneofUint32: UInt32 {
  44. get {
  45. if case .oneofUint32(let v)? = oneofField {return v}
  46. return 0
  47. }
  48. set {oneofField = .oneofUint32(newValue)}
  49. }
  50. var oneofNestedMessage: SwiftProtoTesting_Merging_TestMessage.NestedMessage {
  51. get {
  52. if case .oneofNestedMessage(let v)? = oneofField {return v}
  53. return SwiftProtoTesting_Merging_TestMessage.NestedMessage()
  54. }
  55. set {oneofField = .oneofNestedMessage(newValue)}
  56. }
  57. var oneofString: String {
  58. get {
  59. if case .oneofString(let v)? = oneofField {return v}
  60. return String()
  61. }
  62. set {oneofField = .oneofString(newValue)}
  63. }
  64. var oneofBytes: Data {
  65. get {
  66. if case .oneofBytes(let v)? = oneofField {return v}
  67. return Data()
  68. }
  69. set {oneofField = .oneofBytes(newValue)}
  70. }
  71. var unknownFields = SwiftProtobuf.UnknownStorage()
  72. enum OneOf_OneofField: Equatable, Sendable {
  73. case oneofUint32(UInt32)
  74. case oneofNestedMessage(SwiftProtoTesting_Merging_TestMessage.NestedMessage)
  75. case oneofString(String)
  76. case oneofBytes(Data)
  77. }
  78. struct NestedMessage: Sendable {
  79. // SwiftProtobuf.Message conformance is added in an extension below. See the
  80. // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
  81. // methods supported on all messages.
  82. var a: Int32 {
  83. get {_a ?? 0}
  84. set {_a = newValue}
  85. }
  86. /// Returns true if `a` has been explicitly set.
  87. var hasA: Bool {self._a != nil}
  88. /// Clears the value of `a`. Subsequent reads from it will return its default value.
  89. mutating func clearA() {self._a = nil}
  90. var b: Int32 {
  91. get {_b ?? 0}
  92. set {_b = newValue}
  93. }
  94. /// Returns true if `b` has been explicitly set.
  95. var hasB: Bool {self._b != nil}
  96. /// Clears the value of `b`. Subsequent reads from it will return its default value.
  97. mutating func clearB() {self._b = nil}
  98. var c: Int32 {
  99. get {_c ?? 0}
  100. set {_c = newValue}
  101. }
  102. /// Returns true if `c` has been explicitly set.
  103. var hasC: Bool {self._c != nil}
  104. /// Clears the value of `c`. Subsequent reads from it will return its default value.
  105. mutating func clearC() {self._c = nil}
  106. var unknownFields = SwiftProtobuf.UnknownStorage()
  107. init() {}
  108. fileprivate var _a: Int32? = nil
  109. fileprivate var _b: Int32? = nil
  110. fileprivate var _c: Int32? = nil
  111. }
  112. init() {}
  113. }
  114. struct SwiftProtoTesting_Merging_TestParsingMerge: Sendable {
  115. // SwiftProtobuf.Message conformance is added in an extension below. See the
  116. // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
  117. // methods supported on all messages.
  118. var optionalMessage: SwiftProtoTesting_Merging_TestMessage {
  119. get {_optionalMessage ?? SwiftProtoTesting_Merging_TestMessage()}
  120. set {_optionalMessage = newValue}
  121. }
  122. /// Returns true if `optionalMessage` has been explicitly set.
  123. var hasOptionalMessage: Bool {self._optionalMessage != nil}
  124. /// Clears the value of `optionalMessage`. Subsequent reads from it will return its default value.
  125. mutating func clearOptionalMessage() {self._optionalMessage = nil}
  126. var repeatedMessage: [SwiftProtoTesting_Merging_TestMessage] = []
  127. var unknownFields = SwiftProtobuf.UnknownStorage()
  128. struct RepeatedFieldsGenerator: Sendable {
  129. // SwiftProtobuf.Message conformance is added in an extension below. See the
  130. // `Message` and `Message+*Additions` files in the SwiftProtobuf library for
  131. // methods supported on all messages.
  132. var field1: [SwiftProtoTesting_Merging_TestMessage] = []
  133. var field2: [SwiftProtoTesting_Merging_TestMessage] = []
  134. var unknownFields = SwiftProtobuf.UnknownStorage()
  135. init() {}
  136. }
  137. init() {}
  138. fileprivate var _optionalMessage: SwiftProtoTesting_Merging_TestMessage? = nil
  139. }
  140. // MARK: - Code below here is support for the SwiftProtobuf runtime.
  141. fileprivate let _protobuf_package = "swift_proto_testing.merging"
  142. extension SwiftProtoTesting_Merging_TestMessage: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
  143. static let protoMessageName: String = _protobuf_package + ".TestMessage"
  144. static let _protobuf_nameMap = SwiftProtobuf._NameMap(bytecode: "\0\u{4}o\u{1}oneof_uint32\0\u{3}oneof_nested_message\0\u{3}oneof_string\0\u{3}oneof_bytes\0")
  145. mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
  146. while let fieldNumber = try decoder.nextFieldNumber() {
  147. // The use of inline closures is to circumvent an issue where the compiler
  148. // allocates stack space for every case branch when no optimizations are
  149. // enabled. https://github.com/apple/swift-protobuf/issues/1034
  150. switch fieldNumber {
  151. case 111: try {
  152. var v: UInt32?
  153. try decoder.decodeSingularUInt32Field(value: &v)
  154. if let v = v {
  155. if self.oneofField != nil {try decoder.handleConflictingOneOf()}
  156. self.oneofField = .oneofUint32(v)
  157. }
  158. }()
  159. case 112: try {
  160. var v: SwiftProtoTesting_Merging_TestMessage.NestedMessage?
  161. var hadOneofValue = false
  162. if let current = self.oneofField {
  163. hadOneofValue = true
  164. if case .oneofNestedMessage(let m) = current {v = m}
  165. }
  166. try decoder.decodeSingularMessageField(value: &v)
  167. if let v = v {
  168. if hadOneofValue {try decoder.handleConflictingOneOf()}
  169. self.oneofField = .oneofNestedMessage(v)
  170. }
  171. }()
  172. case 113: try {
  173. var v: String?
  174. try decoder.decodeSingularStringField(value: &v)
  175. if let v = v {
  176. if self.oneofField != nil {try decoder.handleConflictingOneOf()}
  177. self.oneofField = .oneofString(v)
  178. }
  179. }()
  180. case 114: try {
  181. var v: Data?
  182. try decoder.decodeSingularBytesField(value: &v)
  183. if let v = v {
  184. if self.oneofField != nil {try decoder.handleConflictingOneOf()}
  185. self.oneofField = .oneofBytes(v)
  186. }
  187. }()
  188. default: break
  189. }
  190. }
  191. }
  192. func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
  193. // The use of inline closures is to circumvent an issue where the compiler
  194. // allocates stack space for every if/case branch local when no optimizations
  195. // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
  196. // https://github.com/apple/swift-protobuf/issues/1182
  197. switch self.oneofField {
  198. case .oneofUint32?: try {
  199. guard case .oneofUint32(let v)? = self.oneofField else { preconditionFailure() }
  200. try visitor.visitSingularUInt32Field(value: v, fieldNumber: 111)
  201. }()
  202. case .oneofNestedMessage?: try {
  203. guard case .oneofNestedMessage(let v)? = self.oneofField else { preconditionFailure() }
  204. try visitor.visitSingularMessageField(value: v, fieldNumber: 112)
  205. }()
  206. case .oneofString?: try {
  207. guard case .oneofString(let v)? = self.oneofField else { preconditionFailure() }
  208. try visitor.visitSingularStringField(value: v, fieldNumber: 113)
  209. }()
  210. case .oneofBytes?: try {
  211. guard case .oneofBytes(let v)? = self.oneofField else { preconditionFailure() }
  212. try visitor.visitSingularBytesField(value: v, fieldNumber: 114)
  213. }()
  214. case nil: break
  215. }
  216. try unknownFields.traverse(visitor: &visitor)
  217. }
  218. static func ==(lhs: SwiftProtoTesting_Merging_TestMessage, rhs: SwiftProtoTesting_Merging_TestMessage) -> Bool {
  219. if lhs.oneofField != rhs.oneofField {return false}
  220. if lhs.unknownFields != rhs.unknownFields {return false}
  221. return true
  222. }
  223. }
  224. extension SwiftProtoTesting_Merging_TestMessage.NestedMessage: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
  225. static let protoMessageName: String = SwiftProtoTesting_Merging_TestMessage.protoMessageName + ".NestedMessage"
  226. static let _protobuf_nameMap = SwiftProtobuf._NameMap(bytecode: "\0\u{1}a\0\u{1}b\0\u{1}c\0")
  227. mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
  228. while let fieldNumber = try decoder.nextFieldNumber() {
  229. // The use of inline closures is to circumvent an issue where the compiler
  230. // allocates stack space for every case branch when no optimizations are
  231. // enabled. https://github.com/apple/swift-protobuf/issues/1034
  232. switch fieldNumber {
  233. case 1: try { try decoder.decodeSingularInt32Field(value: &self._a) }()
  234. case 2: try { try decoder.decodeSingularInt32Field(value: &self._b) }()
  235. case 3: try { try decoder.decodeSingularInt32Field(value: &self._c) }()
  236. default: break
  237. }
  238. }
  239. }
  240. func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
  241. // The use of inline closures is to circumvent an issue where the compiler
  242. // allocates stack space for every if/case branch local when no optimizations
  243. // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
  244. // https://github.com/apple/swift-protobuf/issues/1182
  245. try { if let v = self._a {
  246. try visitor.visitSingularInt32Field(value: v, fieldNumber: 1)
  247. } }()
  248. try { if let v = self._b {
  249. try visitor.visitSingularInt32Field(value: v, fieldNumber: 2)
  250. } }()
  251. try { if let v = self._c {
  252. try visitor.visitSingularInt32Field(value: v, fieldNumber: 3)
  253. } }()
  254. try unknownFields.traverse(visitor: &visitor)
  255. }
  256. static func ==(lhs: SwiftProtoTesting_Merging_TestMessage.NestedMessage, rhs: SwiftProtoTesting_Merging_TestMessage.NestedMessage) -> Bool {
  257. if lhs._a != rhs._a {return false}
  258. if lhs._b != rhs._b {return false}
  259. if lhs._c != rhs._c {return false}
  260. if lhs.unknownFields != rhs.unknownFields {return false}
  261. return true
  262. }
  263. }
  264. extension SwiftProtoTesting_Merging_TestParsingMerge: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
  265. static let protoMessageName: String = _protobuf_package + ".TestParsingMerge"
  266. static let _protobuf_nameMap = SwiftProtobuf._NameMap(bytecode: "\0\u{3}optional_message\0\u{3}repeated_message\0")
  267. mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
  268. while let fieldNumber = try decoder.nextFieldNumber() {
  269. // The use of inline closures is to circumvent an issue where the compiler
  270. // allocates stack space for every case branch when no optimizations are
  271. // enabled. https://github.com/apple/swift-protobuf/issues/1034
  272. switch fieldNumber {
  273. case 1: try { try decoder.decodeSingularMessageField(value: &self._optionalMessage) }()
  274. case 2: try { try decoder.decodeRepeatedMessageField(value: &self.repeatedMessage) }()
  275. default: break
  276. }
  277. }
  278. }
  279. func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
  280. // The use of inline closures is to circumvent an issue where the compiler
  281. // allocates stack space for every if/case branch local when no optimizations
  282. // are enabled. https://github.com/apple/swift-protobuf/issues/1034 and
  283. // https://github.com/apple/swift-protobuf/issues/1182
  284. try { if let v = self._optionalMessage {
  285. try visitor.visitSingularMessageField(value: v, fieldNumber: 1)
  286. } }()
  287. if !self.repeatedMessage.isEmpty {
  288. try visitor.visitRepeatedMessageField(value: self.repeatedMessage, fieldNumber: 2)
  289. }
  290. try unknownFields.traverse(visitor: &visitor)
  291. }
  292. static func ==(lhs: SwiftProtoTesting_Merging_TestParsingMerge, rhs: SwiftProtoTesting_Merging_TestParsingMerge) -> Bool {
  293. if lhs._optionalMessage != rhs._optionalMessage {return false}
  294. if lhs.repeatedMessage != rhs.repeatedMessage {return false}
  295. if lhs.unknownFields != rhs.unknownFields {return false}
  296. return true
  297. }
  298. }
  299. extension SwiftProtoTesting_Merging_TestParsingMerge.RepeatedFieldsGenerator: SwiftProtobuf.Message, SwiftProtobuf._MessageImplementationBase, SwiftProtobuf._ProtoNameProviding {
  300. static let protoMessageName: String = SwiftProtoTesting_Merging_TestParsingMerge.protoMessageName + ".RepeatedFieldsGenerator"
  301. static let _protobuf_nameMap = SwiftProtobuf._NameMap(bytecode: "\0\u{1}field1\0\u{1}field2\0")
  302. mutating func decodeMessage<D: SwiftProtobuf.Decoder>(decoder: inout D) throws {
  303. while let fieldNumber = try decoder.nextFieldNumber() {
  304. // The use of inline closures is to circumvent an issue where the compiler
  305. // allocates stack space for every case branch when no optimizations are
  306. // enabled. https://github.com/apple/swift-protobuf/issues/1034
  307. switch fieldNumber {
  308. case 1: try { try decoder.decodeRepeatedMessageField(value: &self.field1) }()
  309. case 2: try { try decoder.decodeRepeatedMessageField(value: &self.field2) }()
  310. default: break
  311. }
  312. }
  313. }
  314. func traverse<V: SwiftProtobuf.Visitor>(visitor: inout V) throws {
  315. if !self.field1.isEmpty {
  316. try visitor.visitRepeatedMessageField(value: self.field1, fieldNumber: 1)
  317. }
  318. if !self.field2.isEmpty {
  319. try visitor.visitRepeatedMessageField(value: self.field2, fieldNumber: 2)
  320. }
  321. try unknownFields.traverse(visitor: &visitor)
  322. }
  323. static func ==(lhs: SwiftProtoTesting_Merging_TestParsingMerge.RepeatedFieldsGenerator, rhs: SwiftProtoTesting_Merging_TestParsingMerge.RepeatedFieldsGenerator) -> Bool {
  324. if lhs.field1 != rhs.field1 {return false}
  325. if lhs.field2 != rhs.field2 {return false}
  326. if lhs.unknownFields != rhs.unknownFields {return false}
  327. return true
  328. }
  329. }