/** * Sends command message. * * <p> * This method wraps another buffer within command byte and also checks for command success. * </p> * * @version 0.1.2 * @since 0.1.2 * @param OTS_Buffer $message Command to be send. * @return OTS_Buffer Respond. * @throws E_OTS_ErrorCode If failure respond received. * @throws E_OTS_OutOfBuffer When there is read attemp after end of packet stream. */ private function sendCommand(OTS_Buffer $message) { // prepends command byte $buffer = new OTS_Buffer(); $buffer->putChar(self::REQUEST_COMMAND); $buffer->putString($message->getBuffer(), false); // sends command $buffer = $this->send($buffer); $byte = $buffer->getChar(); // checks for error code if ($byte != self::RESPOND_COMMAND_OK) { throw new E_OTS_ErrorCode($byte, $buffer->getString()); } // returns respond with reseted position $buffer->setPos(0); return $buffer; }