1
0
Fork 0

the received packet may be a message or a bundle

This commit is contained in:
Kevin Matz 2023-05-15 11:24:19 -04:00
parent 31ec3ade78
commit 0bd30d1151
1 changed files with 19 additions and 2 deletions

View File

@ -113,11 +113,28 @@ void Receiver::scheduleBundle(const std::shared_ptr<Bundle> msg) const
*/
void Receiver::rxPacket(std::shared_ptr<bufferstream> buffer) const
{
while (buffer->good()) {
auto msg = std::make_shared<Message>();
auto packet = [&](std::shared_ptr<Message> msg)
{
msg->iStream(buffer);
if (!buffer->fail())
dispatch(msg);
};
while (buffer->available() && buffer->good())
{
/// > \cite Spec10 The contents of an OSC packet must be either an OSC Message or
/// > an OSC Bundle. The first byte of the packets contents unambiguously
/// > distinguishes between these two alternatives.
switch (buffer->peek()) {
case '/':
packet(std::make_shared<Message>());
break;
case '#':
packet(std::make_shared<Bundle>());
break;
default:
buffer->setstate(std::ios::failbit);
}
}
}