当前位置: 首页>>代码示例>>PHP>>正文


PHP WireFormat::getWireType方法代码示例

本文整理汇总了PHP中Protobuf\WireFormat::getWireType方法的典型用法代码示例。如果您正苦于以下问题:PHP WireFormat::getWireType方法的具体用法?PHP WireFormat::getWireType怎么用?PHP WireFormat::getWireType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Protobuf\WireFormat的用法示例。


在下文中一共展示了WireFormat::getWireType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: assertWireType

 /**
  * Assert the wire type match
  *
  * @param integer $wire
  * @param integer $type
  */
 public static function assertWireType($wire, $type)
 {
     $expected = WireFormat::getWireType($type, $wire);
     if ($wire !== $expected) {
         throw new RuntimeException(sprintf("Expected wire type %s but got %s for type %s.", $expected, $wire, $type));
     }
 }
开发者ID:protobuf-php,项目名称:protobuf,代码行数:13,代码来源:WireFormat.php

示例2: generateFieldWriteStatement

 /**
  * @param \Protobuf\Compiler\Entity             $entity
  * @param \google\protobuf\FieldDescriptorProto $field
  *
  * @return string[]
  */
 public function generateFieldWriteStatement(Entity $entity, FieldDescriptorProto $field)
 {
     $body = [];
     $name = $field->getName();
     $type = $field->getType();
     $rule = $field->getLabel();
     $tag = $field->getNumber();
     $options = $field->getOptions();
     $variable = $this->targetVar ?: '$this->' . $name;
     $isPack = $options ? $options->getPacked() : false;
     $wire = $isPack ? WireFormat::WIRE_LENGTH : WireFormat::getWireType($type->value(), null);
     $key = WireFormat::getFieldKey($tag, $wire);
     if ($rule === Label::LABEL_REPEATED() && $isPack) {
         $itemValSttm = $type === Type::TYPE_ENUM() ? '$val->value()' : '$val';
         $body[] = '$innerSize   = 0;';
         $body[] = '$calculator  = $sizeContext->getSizeCalculator();';
         $body[] = null;
         $body[] = 'foreach (' . $variable . ' as $val) {';
         $body[] = '    $innerSize += ' . $this->generateValueSizeStatement($type->value(), $itemValSttm) . ';';
         $body[] = '}';
         $body[] = null;
         $body[] = '$writer->writeVarint($stream, ' . $key . ');';
         $body[] = '$writer->writeVarint($stream, $innerSize);';
         $body[] = null;
         $body[] = 'foreach (' . $variable . ' as $val) {';
         $body[] = '    ' . $this->generateWriteScalarStatement($type->value(), $itemValSttm) . ';';
         $body[] = '}';
         return $body;
     }
     if ($type === Type::TYPE_MESSAGE() && $rule === Label::LABEL_REPEATED()) {
         $body[] = 'foreach (' . $variable . ' as $val) {';
         $body[] = '    $writer->writeVarint($stream, ' . $key . ');';
         $body[] = '    $writer->writeVarint($stream, $val->serializedSize($sizeContext));';
         $body[] = '    $val->writeTo($context);';
         $body[] = '}';
         return $body;
     }
     if ($type === Type::TYPE_ENUM() && $rule === LABEL::LABEL_REPEATED()) {
         $body[] = 'foreach (' . $variable . ' as $val) {';
         $body[] = '    $writer->writeVarint($stream, ' . $key . ');';
         $body[] = '    ' . $this->generateWriteScalarStatement($type->value(), '$val->value()') . ';';
         $body[] = '}';
         return $body;
     }
     if ($rule === Label::LABEL_REPEATED()) {
         $body[] = 'foreach (' . $variable . ' as $val) {';
         $body[] = '    $writer->writeVarint($stream, ' . $key . ');';
         $body[] = '    ' . $this->generateWriteScalarStatement($type->value(), '$val') . ';';
         $body[] = '}';
         return $body;
     }
     if ($type === Type::TYPE_ENUM()) {
         $body[] = sprintf('$writer->writeVarint($stream, %s);', $key);
         $body[] = $this->generateWriteScalarStatement($type->value(), $variable . '->value()') . ';';
         return $body;
     }
     if ($type !== Type::TYPE_MESSAGE()) {
         $body[] = sprintf('$writer->writeVarint($stream, %s);', $key);
         $body[] = $this->generateWriteScalarStatement($type->value(), $variable) . ';';
         return $body;
     }
     $body[] = '$writer->writeVarint($stream, ' . $key . ');';
     $body[] = '$writer->writeVarint($stream, ' . $variable . '->serializedSize($sizeContext));';
     $body[] = $variable . '->writeTo($context);';
     return $body;
 }
开发者ID:protobuf-php,项目名称:protobuf-plugin,代码行数:72,代码来源:WriteFieldStatementGenerator.php


注:本文中的Protobuf\WireFormat::getWireType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。