Example #1
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;
     }
 }
Example #2
0
 public function writeContextSerialize()
 {
     global $context;
     if (empty($context)) {
         return '';
     }
     $obj = new \Thrift\ContextSeralize($context);
     $transObj = new \Thrift\Transport\TMemoryBuffer();
     $protocol = new \Thrift\Protocol\TBinaryProtocol($transObj);
     $obj->write($protocol);
     return $transObj->getBuffer();
 }