@@ -2,7 +2,7 @@ import CLibMongoC
22import Foundation
33
44/// A struct representing a network address, consisting of a host and port.
5- public struct ServerAddress : Equatable {
5+ public struct ServerAddress : Equatable , Hashable {
66 /// The hostname or IP address.
77 public let host : String
88
@@ -67,25 +67,68 @@ private struct HelloResponse: Decodable {
6767/// A struct describing a mongod or mongos process.
6868public struct ServerDescription {
6969 /// The possible types for a server.
70- public enum ServerType : String , Equatable {
70+ public struct ServerType : RawRepresentable , Equatable {
7171 /// A standalone mongod server.
72- case standalone = " Standalone "
72+ public static let standalone = ServerType ( . standalone)
73+
7374 /// A router to a sharded cluster, i.e. a mongos server.
74- case mongos = " Mongos "
75+ public static let mongos = ServerType ( . mongos)
76+
7577 /// A replica set member which is not yet checked, but another member thinks it is the primary.
76- case possiblePrimary = " PossiblePrimary "
78+ public static let possiblePrimary = ServerType ( . possiblePrimary)
79+
7780 /// A replica set primary.
78- case rsPrimary = " RSPrimary "
81+ public static let rsPrimary = ServerType ( . rsPrimary)
82+
7983 /// A replica set secondary.
80- case rsSecondary = " RSSecondary "
84+ public static let rsSecondary = ServerType ( . rsSecondary)
85+
8186 /// A replica set arbiter.
82- case rsArbiter = " RSArbiter "
87+ public static let rsArbiter = ServerType ( . rsArbiter)
88+
8389 /// A replica set member that is none of the other types (a passive, for example).
84- case rsOther = " RSOther "
90+ public static let rsOther = ServerType ( . rsOther)
91+
8592 /// A replica set member that does not report a set name or a hosts list.
86- case rsGhost = " RSGhost "
93+ public static let rsGhost = ServerType ( . rsGhost)
94+
8795 /// A server type that is not yet known.
88- case unknown = " Unknown "
96+ public static let unknown = ServerType ( . unknown)
97+
98+ /// A load balancer.
99+ public static let loadBalancer = ServerType ( . loadBalancer)
100+
101+ /// Internal representation of server type. If enums could be marked non-exhaustive in Swift, this would be the
102+ /// public representation too.
103+ private enum _ServerType : String , Equatable {
104+ case standalone = " Standalone "
105+ case mongos = " Mongos "
106+ case possiblePrimary = " PossiblePrimary "
107+ case rsPrimary = " RSPrimary "
108+ case rsSecondary = " RSSecondary "
109+ case rsArbiter = " RSArbiter "
110+ case rsOther = " RSOther "
111+ case rsGhost = " RSGhost "
112+ case unknown = " Unknown "
113+ case loadBalancer = " LoadBalancer "
114+ }
115+
116+ private let _serverType : _ServerType
117+
118+ private init ( _ _type: _ServerType ) {
119+ self . _serverType = _type
120+ }
121+
122+ public var rawValue : String {
123+ self . _serverType. rawValue
124+ }
125+
126+ public init ? ( rawValue: String ) {
127+ guard let _type = _ServerType ( rawValue: rawValue) else {
128+ return nil
129+ }
130+ self . _serverType = _type
131+ }
89132 }
90133
91134 /// The hostname or IP and the port number that the client connects to. Note that this is not the "me" field in the
@@ -206,17 +249,52 @@ extension ServerDescription: Equatable {
206249/// which servers are up, what type of servers they are, which is primary, and so on.
207250public struct TopologyDescription : Equatable {
208251 /// The possible types for a topology.
209- public enum TopologyType : String , Equatable {
252+ public struct TopologyType : RawRepresentable , Equatable {
210253 /// A single mongod server.
211- case single = " Single "
254+ public static let single = TopologyType ( . single)
255+
212256 /// A replica set with no primary.
213- case replicaSetNoPrimary = " ReplicaSetNoPrimary "
257+ public static let replicaSetNoPrimary = TopologyType ( . replicaSetNoPrimary)
258+
214259 /// A replica set with a primary.
215- case replicaSetWithPrimary = " ReplicaSetWithPrimary "
260+ public static let replicaSetWithPrimary = TopologyType ( . replicaSetWithPrimary)
261+
216262 /// Sharded topology.
217- case sharded = " Sharded "
263+ public static let sharded = TopologyType ( . sharded)
264+
218265 /// A topology whose type is not yet known.
219- case unknown = " Unknown "
266+ public static let unknown = TopologyType ( . unknown)
267+
268+ /// A topology with a load balancer in front.
269+ public static let loadBalanced = TopologyType ( . loadBalanced)
270+
271+ /// Internal representation of topology type. If enums could be marked non-exhaustive in Swift, this would be
272+ /// the public representation too.
273+ private enum _TopologyType : String , Equatable {
274+ case single = " Single "
275+ case replicaSetNoPrimary = " ReplicaSetNoPrimary "
276+ case replicaSetWithPrimary = " ReplicaSetWithPrimary "
277+ case sharded = " Sharded "
278+ case unknown = " Unknown "
279+ case loadBalanced = " LoadBalanced "
280+ }
281+
282+ private let _topologyType : _TopologyType
283+
284+ private init ( _ _type: _TopologyType ) {
285+ self . _topologyType = _type
286+ }
287+
288+ public var rawValue : String {
289+ self . _topologyType. rawValue
290+ }
291+
292+ public init ? ( rawValue: String ) {
293+ guard let _type = _TopologyType ( rawValue: rawValue) else {
294+ return nil
295+ }
296+ self . _topologyType = _type
297+ }
220298 }
221299
222300 /// The type of this topology.
0 commit comments