Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get messages from packets? #16

Closed
arlomedia opened this issue Dec 13, 2024 · 2 comments
Closed

How to get messages from packets? #16

arlomedia opened this issue Dec 13, 2024 · 2 comments

Comments

@arlomedia
Copy link

arlomedia commented Dec 13, 2024

Can someone show how to get an OSCMessage from the OSCPacket that the client and server callback functions deliver?

The OSCKit ReadMe shows the callback functions but with no code inside. This issue shows a cast from OSCPacket to OSCBundle, but Xcode tells me that will always fail, and if I try it anyway it does fail. I'm looking at the source code for OSCPacket, but I don't understand what it's doing. When I search the web, I just find other projects that also use the OSCKit, OSCCore or OSCPacket names.

I can see from the debugger output below that the message data I'm looking for is right there in the OSCPacket, but I can't find the syntax for getting it.

Screenshot 2024-12-12 at 4 51 54 PM

@arlomedia
Copy link
Author

arlomedia commented Dec 13, 2024

Searching through the source code, I found let message = OSCKit.message(for: packet), but Xcode won't compile that and says 'message' is inaccessible due to 'internal' protection level. That seems to only process OSCKit's address patterns anyway.

OSCPacket.data() seems more relevant, but the .message(message) syntax is confusing. I think it's just checking the type of the packet data and returning it as message data or bundle data.

I can convert that data to a string and then feed it into OSCMessage(raw: messageString), but that doesn't separate the arguments from the address pattern. Or I could feed it into OSCParser.parseOSCMessage(), but that's a private function.

Surely there is a more direct way to do this. I'm starting to think casting the packet, as in the one bit of example code I've found, is the way, but Xcode still sees those as unrelated types.

@sammysmallman
Copy link
Owner

Hey @arlomedia,

Apologise for the delayed response. OSCPacket is now an enum with associated values. Rather than casting you can switch upon the object.

switch packet {
case let .bundle(bundle):
  print("Received: \(bundle)")
case let .message(message):
  print("Received: \(message)")
}

If you know you know you'll just be receiving OSC Messages you can do the following:

if case let .message(message) = packet {
  print("Received: \(message)")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants