using parser for namespace
This commit is contained in:
parent
0b8be08a54
commit
8bae7d06d2
@ -17,7 +17,7 @@ class SocketParserTest: XCTestCase {
|
||||
"51-/swift,[\"testMultipleItemsWithBufferEmitReturn\",[1,2],{\"test\":\"bob\"},25,\"polo\",{\"_placeholder\":true,\"num\":0}]": ("/swift", ["testMultipleItemsWithBufferEmitReturn", [1, 2], ["test": "bob"], 25, "polo", "~~0"], [], -1),
|
||||
"3/swift,0[[\"test3\",\"test4\"]]": ("/swift", [["test3", "test4"]], [], 0),
|
||||
"61-/swift,9[[1,2],{\"test\":\"bob\"},25,\"polo\",{\"_placeholder\":true,\"num\":0}]": ("/swift", [ [1, 2], ["test": "bob"], 25, "polo", "~~0"], [], 9),
|
||||
"4/swift": ("/swift", [], [], -1),
|
||||
"4/swift,": ("/swift", [], [], -1),
|
||||
"10": ("/swift", [], [], -1)]
|
||||
|
||||
func testDisconnect() {
|
||||
@ -51,12 +51,12 @@ class SocketParserTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testNamespaceErrorParse() {
|
||||
let message = "4/swift"
|
||||
let message = "4/swift,"
|
||||
validateParseResult(message)
|
||||
}
|
||||
|
||||
func testInvalidInput() {
|
||||
let message = "10"
|
||||
let message = "8"
|
||||
let packet = SocketParser.parseString(message)
|
||||
XCTAssertNil(packet)
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ struct GenericParser {
|
||||
if foundRange.location == Int.max {
|
||||
return nil
|
||||
}
|
||||
currentIndex = foundRange.location + 1
|
||||
currentIndex = currentIndex + foundRange.location
|
||||
|
||||
return subString.substringToIndex(foundRange.location)
|
||||
}
|
||||
@ -128,7 +128,7 @@ class SocketParser {
|
||||
var placeholders = -1
|
||||
|
||||
if type == .BinaryEvent || type == .BinaryAck {
|
||||
if let buffer = parser.readUntilStringOccurence("-"), let holders = Int(buffer) where parser.read(1) == "-" {
|
||||
if let buffer = parser.readUntilStringOccurence("-"), let holders = Int(buffer) where parser.read(1)! == "-" {
|
||||
placeholders = holders
|
||||
} else {
|
||||
NSLog("Error parsing \(str)")
|
||||
@ -137,22 +137,12 @@ class SocketParser {
|
||||
|
||||
i = parser.currentIndex - 1
|
||||
}
|
||||
|
||||
if messageCharacters[i + 1] == "/" {
|
||||
nsp = ""
|
||||
|
||||
while ++i < messageCharacters.count {
|
||||
let c = messageCharacters[i]
|
||||
|
||||
if c == "," {
|
||||
break
|
||||
}
|
||||
|
||||
nsp! += String(c)
|
||||
}
|
||||
if parser.currentCharacter == "/" {
|
||||
nsp = parser.readUntilStringOccurence(",")
|
||||
i = parser.currentIndex
|
||||
}
|
||||
|
||||
if i + 1 >= messageCharacters.count {
|
||||
if parser.currentIndex + 1 >= parser.messageCharacters.count {
|
||||
return SocketPacket(type: type, id: id ?? -1,
|
||||
nsp: nsp ?? "/", placeholders: placeholders)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user