• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2024 Google Inc.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 /// Swift specific additions to simplify usage.
9 extension GPBUnknownFields {
10 
11   /// Fetches the first varint for the given field number.
firstVarintnull12   public func firstVarint(_ fieldNumber: Int32) -> UInt64? {
13     var value: UInt64 = 0
14     guard getFirst(fieldNumber, varint: &value) else { return nil }
15     return value
16   }
17 
18   /// Fetches the first fixed32 for the given field number.
firstFixed32null19   public func firstFixed32(_ fieldNumber: Int32) -> UInt32? {
20     var value: UInt32 = 0
21     guard getFirst(fieldNumber, fixed32: &value) else { return nil }
22     return value
23   }
24 
25   /// Fetches the first fixed64 for the given field number.
firstFixed64null26   public func firstFixed64(_ fieldNumber: Int32) -> UInt64? {
27     var value: UInt64 = 0
28     guard getFirst(fieldNumber, fixed64: &value) else { return nil }
29     return value
30   }
31 
32 }
33 
34 /// Map the `NSFastEnumeration` support to a Swift `Sequence`.
35 extension GPBUnknownFields: Sequence {
36   public typealias Element = GPBUnknownField
37 
38   public struct Iterator: IteratorProtocol {
39     var iter: NSFastEnumerationIterator
40 
41     init(_ fields: NSFastEnumeration) {
42       self.iter = NSFastEnumerationIterator(fields)
43     }
44 
nextnull45     public mutating func next() -> GPBUnknownField? {
46       return iter.next() as? GPBUnknownField
47     }
48   }
49 
makeIteratornull50   public func makeIterator() -> Iterator {
51     return Iterator(self)
52   }
53 }
54