/** * test parsing the empty package from the corpus */ public function testParse() { $buf = $this->getBuffer('empty_oscbundle'); $this->_object->setDataString($buf); $this->_object->parse(); $result = $this->_object->getResult(); $this->assertEquals($result['address'], "/"); $this->assertEquals($result['data'], array()); }
/** * parse data until no more buffers remain * * after this method we are always in the done state * since messages may not contain osc bundles. * * @return void */ private function _parseBundles() { $state = $this->_state; $bundlets = $this->_multiByteShift(8, 'array'); $this->_parseTimestamp(); while (!empty($this->_data)) { $bundlesize = hexdec($this->_multiByteShift(4)); if ($bundlesize % 4 !== 0) { $bundlesize++; } $bundledata = $this->_multiByteShift($bundlesize, 'array'); if ($this->_debug) { printf("Found Bundle of length %s\n", $bundlesize); } $bundleparse = new Osc_Parse(); $bundleparse->setDebug($this->_debug); $bundleparse->setData($bundledata); $bundleparse->parse(); if ($this->_debug) { printf("Parsed bundle."); var_dump($bundleparse->getResult()); } $this->_appendStore($bundleparse->getResult()); } $state = Osc_Parse::STATE_DONE; return $state; }
/** * load broken hexfloat lib * * i plan on groking pack/unpack to the extent that i * can do this right in Osc_Parse without needing this. */ require_once 'src/Osc/HexFloat.php'; // create a socket $socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP); $r = socket_bind($socket, $ip, $port); // loop until user interrupt while (true) { // this is what gets each datagram if (socket_recvfrom($socket, $b, 9999, 0, $f, $p)) { // a parser gets instanciated for each datagram $osc = new Osc_Parse(); $osc->setDebug($debug); // pass the datagram buffer $osc->setDataString($b); // start the parser $osc->parse(); // make some output if ($debug) { var_dump($osc); } $r = $osc->getResult(); $r["sourceip"] = $f; $r["sourceport"] = $p; var_dump($r); } }