/** * 序列化成数据包 * @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; }
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; }
/** * @param \ProtobufMessage|Api\Pb\Message\RpbGetReq|Api\Pb\Message\RpbPutReq|Api\Pb\Message\RpbDelReq $message * @param Command $command */ protected function setOptionsOnMessage(\ProtobufMessage &$message, Command $command) { if ($command->getParameter('n_val')) { $message->setNVal($command->getParameter('n_val')); } if ($command->getParameter('r')) { $message->setR($command->getParameter('r')); } if ($command->getParameter('w')) { $message->setW($command->getParameter('w')); } if ($command->getParameter('pr')) { $message->setPr($command->getParameter('pr')); } if ($command->getParameter('pw')) { $message->setPw($command->getParameter('pw')); } if ($command->getParameter('dw')) { $message->setDw($command->getParameter('dw')); } if ($command->getParameter('rw')) { $message->setRw($command->getParameter('rw')); } if ($command->getParameter('basic_quorum')) { $message->setBasicQuorum($command->getParameter('basic_quorum')); } if ($command->getParameter('notfound_ok')) { $message->setNotfoundOk($command->getParameter('notfound_ok')); } if ($command->getParameter('if_modified')) { $message->setIfModified($command->getParameter('if_modified')); } if ($command->getParameter('if_not_modified')) { $message->setIfNotModified($command->getParameter('if_not_modified')); } if ($command->getParameter('return_body')) { $message->setReturnBody($command->getParameter('return_body')); } if ($command->getParameter('sloppy_quorum')) { $message->setSloppyQuorum($command->getParameter('sloppy_quorum')); } if ($command->getParameter('timeout')) { $message->setTimeout($command->getParameter('timeout')); } }