#include <OSCUnpacker.h>
Public Member Functions | |
void | init () |
void | reset () |
bool | unpackDouble (double *out) |
Copy a double-precision floating point number into *out. | |
bool | unpackFloat (float *out) |
Copy a single-precision floating point number into *out. | |
bool | unpackHyper (int64_t *out) |
Copy an eight-byte integer into *out. | |
bool | unpackInt (int32_t *out) |
Copy a four-byte integer into *out. | |
bool | unpackString (std::string *out) |
Copy a null-terminated string into *out. | |
bool | unpackBlob (std::string *out) |
Copy a counted string (blob) into *out. | |
bool | skipDouble () |
Skip eight bytes of data. | |
bool | skipFloat () |
Skip four bytes of data. | |
bool | skipHyper () |
Skip eight bytes of data. | |
bool | skipInt () |
Skip four bytes of data. | |
bool | skipString () |
Skip a null-terminated string in the data. | |
bool | skipBlob () |
Skip a blob (counted string) in the data. | |
void | setData (const std::string &data) |
Protected Member Functions | |
std::string * | getDataPointer () |
bool | unpackBytes (char *out, int bytes) |
Copy bytes octets of data into *out, padding to keep alignment. | |
bool | skipBytes (int bytes) |
Skip bytes octets of data, adding padding to keep alignment. | |
int | getPosition () |
void | setPosition (int p) |
Does not automatically process type tags.
This class unpacks four-byte aligned binary data packed in the Open SoundControl format.
Here is a simple example. An OSC packet has been given to us in oscdata
and we would like to unpack it.
If we want to be safe, we should check that our typetags are correct (here, ",if") and that all of the unpack methods return true. (The object into which the data is unpacked will never be invalid after an unsuccessful unpack - if there is some error the result is 0 or an empty string. However, if we can't unpack the arguments we expected, we should probably discard the message.)
bool success; string address; string typetags; int i; float f; OSCUnpacker *p; p = new OSCUnpacker(); p->setData(oscdata); success = p->skipString(); // we pass over the first string, the address success &= p->unpackString(&typetags); if(success) // we have unpacked the typetags { success = false; if(typetags == ",if") { success = p->unpackInt(&i); success &= p->unpackFloat(&f); } } // if success == true, we have correctly unpacked the message. delete p;
Martin Rumori