public function onData($data) { if ($this->currentMessage) { $overflow = $this->currentMessage->parseData($data); // json_encode can slow things down here //$this->debug("onData: " . json_encode($overflow) . ""); if ($overflow === false) { // there was not enough data to complete the message // leave this as the currentParser return; } $this->handleMessage($this->currentMessage); $this->currentMessage = null; if (strlen($overflow) > 0) { $this->onData($overflow); } return; } if (strlen($data) == 0) { return; } $type = $data[0]; $message = Message::createMessageFromIdentifier($type); if ($message !== false) { $this->currentMessage = $message; $this->onData($data); } // if (in_array($type, ['R', 'S', 'D', 'K', '2', '3', 'C', 'd', 'c', 'G', 'H', 'W', 'D', 'I', 'E', 'V', 'n', 'N', 'A', 't', '1', 's', 'Z', 'T'])) { // $this->currentParser = [$this, 'parse1PlusLenMessage']; // call_user_func($this->currentParser, $data); // } else { // echo "Unhandled message \"".$type."\""; // } }