function testEncodeVarintFloat()
 {
     foreach ($this->tests as $i => $enc) {
         if (!hasExactRepresentation($i) || $i < 0) {
             continue;
         }
         if (is_string($i)) {
             $i = (double) $i;
         }
         $result = Protobuf::encode_varint_float($i);
         $this->assertBinaryEqual($enc, $result, "Failed to encode_varint_float({$i})");
     }
 }
Exemple #2
0
 public function __toString()
 {
     return '' . Protobuf::toString('unknown', $this->_unknown) . Protobuf::toString('logGroupList_', $this->logGroupList_);
 }
Exemple #3
0
 public function __toString()
 {
     return '' . Protobuf::toString('unknown', $this->_unknown) . Protobuf::toString('logs_', $this->logs_) . Protobuf::toString('reserved_', $this->reserved_) . Protobuf::toString('topic_', $this->topic_) . Protobuf::toString('source_', $this->source_);
 }
Exemple #4
0
 function update()
 {
     $id = $this->get_id();
     $response_data = $this->get_data_array();
     if (isset($this->req->data->name)) {
         $responseemail_orm = ORM::factory('responseemail')->where('name', $this->req->data->name)->find();
         if ($responseemail_orm->loaded) {
             $this->respNameError();
             exit;
         }
     }
     $db = Database::instance();
     $db->query('begin');
     $responseemail_orm = ORM::factory('responseemail', $id);
     if ($responseemail_orm->loaded) {
         $using = $this->is_using("responseemail", $id);
         foreach ($this->req->data as $key => $value) {
             $responseemail_orm->{$key} = $value;
         }
         $responseemail_orm->save();
         if ($responseemail_orm->saved) {
             if ($using) {
                 $pb = new Protobuf();
                 $result = $pb->sendconfig($db);
                 if ($result['status'] === 0) {
                     $db->query('commit');
                     $result = 0;
                     $this->respOk($response_data);
                 } else {
                     $db->query('rollback');
                     $result = -1;
                     if ($result['message']) {
                         $message = "规则下发失败,失败原因:" . $result['message'];
                     } else {
                         $message = "规则下发失败";
                     }
                     $this->respFailed($message);
                 }
             } else {
                 $db->query('commit');
                 $result = 0;
                 $this->respOk($response_data);
             }
         } else {
             $result = -1;
             $message = '修改email响应失败,未知的错误';
             $this->respFailed($message);
         }
         $diff_data = $this->update_data_diff($this->req->data_array, $this->req->oldValues_array);
         $this->operationlog_update($result, $id, $this->req->oldValues->name, $diff_data);
     } else {
         $message = '修改email响应失败,未知的email响应ID';
         $this->respFailed($message);
     }
     return;
 }
Exemple #5
0
 /**
  * Serialize the current object data
  *
  * @param CodecInterface|null $codec
  * @return string
  */
 public function serialize(CodecInterface $codec = null)
 {
     $codec = Protobuf::getCodec($codec);
     return $codec->encode($this);
 }
function size_tests()
{
    run("size_varint", function () {
        for ($i = 0; $i < LOOPS; $i++) {
            Protobuf::size_varint(mt_rand());
        }
    });
}
Exemple #7
0
 /**
  * Read a unknown field from the stream and return its raw bytes
  */
 public static function read_field($fp, $wire_type, &$limit = null)
 {
     switch ($wire_type) {
         case 0:
             // varint
             return Protobuf::read_varint($fp, $limit);
         case 1:
             // 64bit
             $limit -= 8;
             return fread($fp, 8);
         case 2:
             // length delimited
             $len = Protobuf::read_varint($fp, $limit);
             $limit -= $len;
             return fread($fp, $len);
             //case 3: // Start group TODO we must keep looping until we find the closing end grou
             //case 4: // End group - We should never skip a end group!
             //	return 0; // Do nothing
         //case 3: // Start group TODO we must keep looping until we find the closing end grou
         //case 4: // End group - We should never skip a end group!
         //	return 0; // Do nothing
         case 5:
             // 32bit
             $limit -= 4;
             return fread($fp, 4);
         default:
             throw new Exception('read_unknown(' . ProtoBuf::get_wiretype($wire_type) . '): Unsupported wire_type');
     }
 }
Exemple #8
0
 function remove()
 {
     $id = $this->get_id();
     $response_data[] = $this->req->data_array;
     $db = Database::instance();
     $db->query('begin');
     $policy_orm = ORM::factory('policy')->where(array('id' => $id, 'deleted' => 0))->find();
     if ($policy_orm->loaded) {
         $policy_orm->deleted = 1;
         $oldname = $policy_orm->name;
         $name = $policy_orm->name . "@" . sprintf("%x", time());
         $policy_orm->name = $name;
         $policy_orm->save();
         if ($policy_orm->saved) {
             if ($policy_orm->saved) {
                 $pb = new Protobuf();
                 $result = $pb->sendconfig($db);
                 if ($result['status'] === 0) {
                     $db->query('commit');
                     $result = 0;
                     $this->respOk($response_data);
                 } else {
                     $db->query('rollback');
                     $result = -1;
                     if ($result['message']) {
                         $message = "规则下发失败,失败原因:" . $result['message'];
                     } else {
                         $message = "规则下发失败";
                     }
                     $this->respFailed($message);
                 }
             } else {
                 $db->query('commit');
                 $result = 0;
                 $this->respOk($response_data);
             }
         } else {
             $result = -1;
             $message = '删除策略失败,未知的错误';
             $this->respFailed($message);
         }
         $this->operationlog_remove($result, $id, $oldname);
     } else {
         $message = '删除策略失败,未知的策略ID';
         $this->respFailed($message);
     }
     return;
 }
Exemple #9
0
 public function __toString()
 {
     return '' . Protobuf::toString('unknown', $this->_unknown) . Protobuf::toString('packages_', $this->packages_);
 }
 public function __toString()
 {
     return '' . Protobuf::toString('unknown', $this->_unknown) . Protobuf::toString('responsegroup_', $this->responsegroup_);
 }
Exemple #11
0
 function remove()
 {
     $id = $this->get_id();
     $response_data[] = $this->req->data_array;
     $db = Database::instance();
     $db->query('begin');
     $dbservice_orm = ORM::factory('auditservice')->where('id', $id)->find();
     if ($dbservice_orm->loaded) {
         $using = $this->is_using("dbservice", $id);
         if ($using) {
             $message = "当前应用配置了审计策略,现在不能删除";
             $this->respFailed($message);
         } else {
             $dbservice_orm->deleted = 1;
             $oldname = $dbservice_orm->name;
             $name = $dbservice_orm->name . "@" . sprintf("%x", time());
             $dbservice_orm->name = $name;
             $dbservice_orm->save();
             if ($dbservice_orm->saved) {
                 if ($using) {
                     $pb = new Protobuf();
                     $result = $pb->sendconfig($db);
                     if ($result['status'] === 0) {
                         $db->query('commit');
                         $result = 0;
                         $this->respOk($response_data);
                     } else {
                         $db->query('rollback');
                         $result = -1;
                         if ($result['message']) {
                             $message = "规则下发失败,失败原因:" . $result['message'];
                         } else {
                             $message = "规则下发失败";
                         }
                         $this->respFailed($message);
                     }
                 } else {
                     $db->query('commit');
                     $result = 0;
                     $this->respOk($response_data);
                 }
             } else {
                 $result = -1;
                 $message = '删除服务失败,未知的错误';
                 $this->respFailed($message);
             }
             $this->operationlog_remove($result, $id, $oldname);
         }
     } else {
         $message = '删除服务失败,未知的数据库服务ID';
         $this->respFailed($message);
     }
     return;
 }
 function testEncodeVarintGMP()
 {
     foreach ($this->tests as $i => $enc) {
         if ($i < 0) {
             continue;
         }
         // Only test positive values
         $result = Protobuf::encode_varint_gmp($i);
         $this->assertBinaryEqual($enc, $result, "Failed to encode_varint_gmp({$i})");
     }
     try {
         Protobuf::encode_varint_gmp("bob");
         $this->fail("Exception should have been thrown");
     } catch (InvalidArgumentException $e) {
     }
     try {
         $result = Protobuf::encode_varint_gmp("-1");
         $this->fail("Exception should have been thrown");
     } catch (InvalidArgumentException $e) {
     }
     try {
         $result = Protobuf::encode_varint_gmp(-1);
         $this->fail("Exception should have been thrown");
     } catch (InvalidArgumentException $e) {
     }
     try {
         $result = Protobuf::encode_varint_gmp("18446744073709551616");
         $this->fail("Exception should have been thrown");
     } catch (InvalidArgumentException $e) {
     }
 }