ExistentialAudio/SwiftOSC

String arg comparison doesn't work as expected

nariakiiwatani opened this issue · 4 comments

Something is wrong with string args in received messages.
Before sending, I get true by comparing argument as string with string literal.
But After Receiving, got false.

I'm not sure it is SwiftOSC's problem or not but
if you know something, please help me.

import SwiftOSC

class ViewController: NSViewController {
	let client = OSCClient(address:"localhost", port:9000)
	var server = OSCServer(address:"", port:9000)

	override func viewDidLoad() {
		super.viewDidLoad()
		server.delegate = self
		server.start()

		let m = OSCMessage(OSCAddressPattern(""), "stringArg")
		print(m.arguments[0] as! String) // stringArg
		print(m.arguments[0] as! String == "stringArg") // true
		client.send(m)
	}
	func didReceive(_ m: SwiftOSC.OSCMessage) {
		print(m.arguments[0] as! String) // stringArg
		print(m.arguments[0] as! String == "stringArg") // false
	}
}

I'm sorry I forgot to mention about version.
I'm using 1a1313c35be59ff5fb156a9c4b157a4ce8ca2506 because my environment is Swift3.
If this issue came from this and had already fixed, feel free to close this issue.

Interesting. I'll take a look to see what happens. My initial guess is either something to do with whitespace or the string encoding. I'll let you know once I get a chance to take a closer look.

My initial look shows that the two strings have a different number of bytes so that confirms my guess. If you compare the strings when encoded into utf8 they are identical. You can use that as a quick fix until I find the specific underlaying problem.

Finally had a chance to take a closer look. Pretty sure I solved the problem. It was an off by one error.