예제 #1
0
 /** Pack data into $this->bin as 4-byte aligned, network-byte order.
  */
 function pack_data($data, $type_hint)
 {
     $bin = "";
     switch ($type_hint) {
         case "T":
         case "F":
         case "N":
         case "I":
             return;
             // These types have no allocated space
         // These types have no allocated space
         case "A":
             foreach ($data as $arg) {
                 $this->pack_data($arg[0], $arg[1]);
             }
             break;
         case "s":
             $data .= "";
             // The builtin \0 terminator is ignored... we must explicitly request one.
             $bin = pack("a*" . $this->get_strpad($data), $data);
             break;
         case "b":
             $this->pack_data(strlen($data->bin), "i");
             $bin = pack("a*" . $this->get_strpad($data->bin), $data->bin);
             break;
         case "i":
             $bin = OSCClient::host_to_network_order(pack("i", $data));
             // Machine-independent size (4-bytes)
             break;
         case "f":
             $bin = OSCClient::host_to_network_order(pack("f", $data));
             // Machine-dependent size
             if (strlen($bin) != 4) {
                 $this->error("Sorry, your machine uses an unsupported single-precision floating point size.");
             }
             break;
         case "d":
             $bin = OSCClient::host_to_network_order(pack("d", $data));
             // Machine-dependent size
             if (strlen($bin) != 8) {
                 $this->error("Sorry, your machine uses an unsupported double-precision floating point size.");
             }
             break;
         case "t":
             if (is_null($data)) {
                 $data = new Timetag();
             }
             $bin = OSCClient::host_to_network_order(pack("L", $data->sec)) . OSCClient::host_to_network_order(pack("L", $data->frac_sec));
             break;
     }
     if (strlen($bin) % 4 != 0) {
         $this->error("{$data} failed to align properly, size is " . strlen($bin) . " bytes.");
     }
     $this->bin .= $bin;
 }