Esempio n. 1
0
 public static function encode_msg($req)
 {
     $transport = new Thrift\Transport\TMemoryBuffer();
     $protocol = new Thrift\Protocol\TBinaryProtocol($transport);
     $req->write($protocol);
     return $transport->getBuffer();
 }
Esempio n. 2
0
 public static function readContextSerialize($buf)
 {
     // 判断是否是TBinaryProtocol
     $sz = unpack('N', $buf);
     if ((int) ($sz[1] & \Thrift\Protocol\TBinaryProtocol::VERSION_MASK) != (int) \Thrift\Protocol\TBinaryProtocol::VERSION_1) {
         return 0;
     }
     $totallength = \Thrift\Factory\TStringFuncFactory::create()->strlen($buf);
     global $context;
     $obj = new \Thrift\ContextSeralize($context);
     $transObj = new \Thrift\Transport\TMemoryBuffer($buf);
     $protocol = new \Thrift\Protocol\TBinaryProtocol($transObj);
     $flag = $obj->read($protocol);
     if ($flag) {
         return $totallength - \Thrift\Factory\TStringFuncFactory::create()->strlen($transObj->getBuffer());
     } else {
         return 0;
     }
 }