Esempio n. 1
0
 /**
  * @return null
  * @throws Exception
  */
 public function send()
 {
     $message = '';
     if (method_exists($this->requestMessage, "serializeToString")) {
         $message = $this->requestMessage->serializeToString();
     }
     $this->debug($this->requestMessage);
     $packedMessage = $this->packMessage($this->messageCode, $message);
     if ($this->connection === false) {
         $this->connection = null;
         return false;
     }
     $written = fwrite($this->connection, $packedMessage);
     if (!$written) {
         throw new Api\Exception('Failed to write to socket.');
     }
     $length = $this->readMessageLength();
     if ($length > 1000000000) {
         throw new Api\Exception('Abnormally high message length detected, possible HTTP response, verify connection port.');
     }
     $message_code = $this->readMessageCode();
     $message = $this->readMessage($length);
     $this->parseResponse($message_code, $message);
     return $this->success;
 }
Esempio n. 2
0
 /**
  * 序列化成数据包
  * @param \ProtobufMessage $proto 协议
  * @return \CatLib\Constraint\Network\IPacket
  */
 public function serialize($proto)
 {
     $packet = App::make(IPacket::class);
     $packet->setBody($proto->serializeToString());
     $packet->setProtoID($this->get($proto, $this->protoIDField));
     return $packet;
 }
Esempio n. 3
0
 public function serializeToString()
 {
     $thumb = $this->getThumbnail();
     $this->setThumbnail(null);
     $data = parent::serializeToString();
     $data .= hex2bin('8201');
     $data .= $this->WriteUInt32(strlen($thumb));
     $data .= $thumb;
     $this->setThumbnail($thumb);
     return $data;
 }