@@ -87,54 +87,44 @@ struct SocketPacket {
87
87
}
88
88
89
89
private func completeMessage( message: String , ack: Bool ) -> String {
90
- var restOfMessage = " "
90
+ let restOfMessage : String
91
91
92
92
if data. count == 0 {
93
- return message + " ] "
93
+ return message + " [ ]"
94
94
}
95
95
96
- for arg in data {
97
- if arg is NSDictionary || arg is [ AnyObject ] {
98
- do {
99
- let jsonSend = try NSJSONSerialization . dataWithJSONObject ( arg,
100
- options: NSJSONWritingOptions ( rawValue: 0 ) )
101
- let jsonString = String ( data: jsonSend, encoding: NSUTF8StringEncoding)
102
-
103
- restOfMessage += jsonString! + " , "
104
- } catch {
105
- DefaultSocketLogger . Logger. error ( " Error creating JSON object in SocketPacket.completeMessage " ,
106
- type: SocketPacket . logType)
107
- }
108
- } else if let str = arg as? String {
109
- restOfMessage += " \" " + ( ( ( str [ " \n " ] <~ " \\ \\ n " ) [ " \r " ] <~ " \\ \\ r " ) [ " \" " ] <~ " \\ \\ \" " ) + " \" , "
110
- } else if arg is NSNull {
111
- restOfMessage += " null, "
112
- } else {
113
- restOfMessage += " \( arg) , "
96
+ do {
97
+ let jsonSend = try NSJSONSerialization . dataWithJSONObject ( data,
98
+ options: NSJSONWritingOptions ( rawValue: 0 ) )
99
+ guard let jsonString = String ( data: jsonSend, encoding: NSUTF8StringEncoding) else {
100
+ return " [] "
114
101
}
102
+
103
+ restOfMessage = jsonString
104
+ } catch {
105
+ DefaultSocketLogger . Logger. error ( " Error creating JSON object in SocketPacket.completeMessage " ,
106
+ type: SocketPacket . logType)
107
+
108
+ restOfMessage = " [] "
115
109
}
116
110
117
- if restOfMessage != " " {
118
- restOfMessage. removeAtIndex ( restOfMessage. endIndex. predecessor ( ) )
119
- }
120
-
121
- return message + restOfMessage + " ] "
111
+ return message + restOfMessage
122
112
}
123
113
124
114
private func createAck( ) -> String {
125
115
let message : String
126
116
127
117
if type == . Ack {
128
118
if nsp == " / " {
129
- message = " 3 \( id) [ "
119
+ message = " 3 \( id) "
130
120
} else {
131
- message = " 3 \( nsp) , \( id) [ "
121
+ message = " 3 \( nsp) , \( id) "
132
122
}
133
123
} else {
134
124
if nsp == " / " {
135
- message = " 6 \( binary. count) - \( id) [ "
125
+ message = " 6 \( binary. count) - \( id) "
136
126
} else {
137
- message = " 6 \( binary. count) - \( nsp) , \( id) [ "
127
+ message = " 6 \( binary. count) - \( nsp) , \( id) "
138
128
}
139
129
}
140
130
@@ -148,29 +138,29 @@ struct SocketPacket {
148
138
if type == . Event {
149
139
if nsp == " / " {
150
140
if id == - 1 {
151
- message = " 2[ "
141
+ message = " 2 "
152
142
} else {
153
- message = " 2 \( id) [ "
143
+ message = " 2 \( id) "
154
144
}
155
145
} else {
156
146
if id == - 1 {
157
- message = " 2 \( nsp) ,[ "
147
+ message = " 2 \( nsp) , "
158
148
} else {
159
- message = " 2 \( nsp) , \( id) [ "
149
+ message = " 2 \( nsp) , \( id) "
160
150
}
161
151
}
162
152
} else {
163
153
if nsp == " / " {
164
154
if id == - 1 {
165
- message = " 5 \( binary. count) -[ "
155
+ message = " 5 \( binary. count) - "
166
156
} else {
167
- message = " 5 \( binary. count) - \( id) [ "
157
+ message = " 5 \( binary. count) - \( id) "
168
158
}
169
159
} else {
170
160
if id == - 1 {
171
- message = " 5 \( binary. count) - \( nsp) ,[ "
161
+ message = " 5 \( binary. count) - \( nsp) , "
172
162
} else {
173
- message = " 5 \( binary. count) - \( nsp) , \( id) [ "
163
+ message = " 5 \( binary. count) - \( nsp) , \( id) "
174
164
}
175
165
}
176
166
}
0 commit comments