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),
|
"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),
|
"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),
|
"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)]
|
"10": ("/swift", [], [], -1)]
|
||||||
|
|
||||||
func testDisconnect() {
|
func testDisconnect() {
|
||||||
@ -51,12 +51,12 @@ class SocketParserTest: XCTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func testNamespaceErrorParse() {
|
func testNamespaceErrorParse() {
|
||||||
let message = "4/swift"
|
let message = "4/swift,"
|
||||||
validateParseResult(message)
|
validateParseResult(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testInvalidInput() {
|
func testInvalidInput() {
|
||||||
let message = "10"
|
let message = "8"
|
||||||
let packet = SocketParser.parseString(message)
|
let packet = SocketParser.parseString(message)
|
||||||
XCTAssertNil(packet)
|
XCTAssertNil(packet)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,7 +55,7 @@ struct GenericParser {
|
|||||||
if foundRange.location == Int.max {
|
if foundRange.location == Int.max {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
currentIndex = foundRange.location + 1
|
currentIndex = currentIndex + foundRange.location
|
||||||
|
|
||||||
return subString.substringToIndex(foundRange.location)
|
return subString.substringToIndex(foundRange.location)
|
||||||
}
|
}
|
||||||
@ -128,7 +128,7 @@ class SocketParser {
|
|||||||
var placeholders = -1
|
var placeholders = -1
|
||||||
|
|
||||||
if type == .BinaryEvent || type == .BinaryAck {
|
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
|
placeholders = holders
|
||||||
} else {
|
} else {
|
||||||
NSLog("Error parsing \(str)")
|
NSLog("Error parsing \(str)")
|
||||||
@ -137,22 +137,12 @@ class SocketParser {
|
|||||||
|
|
||||||
i = parser.currentIndex - 1
|
i = parser.currentIndex - 1
|
||||||
}
|
}
|
||||||
|
if parser.currentCharacter == "/" {
|
||||||
if messageCharacters[i + 1] == "/" {
|
nsp = parser.readUntilStringOccurence(",")
|
||||||
nsp = ""
|
i = parser.currentIndex
|
||||||
|
|
||||||
while ++i < messageCharacters.count {
|
|
||||||
let c = messageCharacters[i]
|
|
||||||
|
|
||||||
if c == "," {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
nsp! += String(c)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if i + 1 >= messageCharacters.count {
|
if parser.currentIndex + 1 >= parser.messageCharacters.count {
|
||||||
return SocketPacket(type: type, id: id ?? -1,
|
return SocketPacket(type: type, id: id ?? -1,
|
||||||
nsp: nsp ?? "/", placeholders: placeholders)
|
nsp: nsp ?? "/", placeholders: placeholders)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user