Skip to content

Commit 3d88671

Browse files
committed
comment some socketpacket methods
1 parent bed5ecd commit 3d88671

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

Source/SocketPacket.swift

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,19 @@ struct SocketPacket {
190190
return str
191191
}
192192

193+
// Called when we have all the binary data for a packet
194+
// calls _fillInPlaceholders, which replaces placeholders with the
195+
// corresponding binary
193196
private mutating func fillInPlaceholders() {
194197
data = data.map({_fillInPlaceholders($0)})
195198
}
196199

197-
private mutating func _fillInPlaceholders(data: AnyObject) -> AnyObject {
198-
switch data {
200+
// Helper method that looks for placeholder strings
201+
// If object is a collection it will recurse
202+
// Returns the object if it is not a placeholder string or the corresponding
203+
// binary data
204+
private func _fillInPlaceholders(object: AnyObject) -> AnyObject {
205+
switch object {
199206
case let string as String where string["~~(\\d)"].groups() != nil:
200207
return binary[Int(string["~~(\\d)"].groups()![1])!]
201208
case let dict as NSDictionary:
@@ -206,8 +213,7 @@ struct SocketPacket {
206213
case let arr as [AnyObject]:
207214
return arr.map({_fillInPlaceholders($0)})
208215
default:
209-
return data
210-
216+
return object
211217
}
212218
}
213219
}
@@ -216,15 +222,15 @@ extension SocketPacket {
216222
private static func findType(binCount: Int, ack: Bool) -> PacketType {
217223
switch binCount {
218224
case 0 where !ack:
219-
return PacketType.Event
225+
return .Event
220226
case 0 where ack:
221-
return PacketType.Ack
227+
return .Ack
222228
case _ where !ack:
223-
return PacketType.BinaryEvent
229+
return .BinaryEvent
224230
case _ where ack:
225-
return PacketType.BinaryAck
231+
return .BinaryAck
226232
default:
227-
return PacketType.Error
233+
return .Error
228234
}
229235
}
230236

@@ -238,6 +244,7 @@ extension SocketPacket {
238244
}
239245

240246
private extension SocketPacket {
247+
// Recursive function that looks for NSData in collections
241248
static func shred(data: AnyObject, inout binary: [NSData]) -> AnyObject {
242249
let placeholder = ["_placeholder": true, "num": binary.count]
243250

@@ -257,6 +264,8 @@ private extension SocketPacket {
257264
}
258265
}
259266

267+
// Removes binary data from emit data
268+
// Returns a type containing the de-binaryed data and the binary
260269
static func deconstructData(data: [AnyObject]) -> ([AnyObject], [NSData]) {
261270
var binary = [NSData]()
262271

0 commit comments

Comments
 (0)