Esempio n. 1
0
 /**
  * Creates \Google\Protobuf\DescriptorProto\ReservedRange object from serialized Protocol Buffers message.
  *
  * @param string $input
  * @param ReservedRange $object
  * @param int $start
  * @param int $end
  *
  * @throws \Exception
  *
  * @return ReservedRange
  */
 public static function fromProtobuf($input, $object = NULL, &$start = 0, $end = NULL)
 {
     if ($object === null) {
         $object = new ReservedRange();
     }
     if ($end === null) {
         $end = strlen($input);
     }
     while ($start < $end) {
         $tag = Binary::decodeVarint($input, $start);
         $wireType = $tag & 0x7;
         $number = $tag >> 3;
         switch ($number) {
             case 1:
                 if ($wireType !== 0) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 0.', $number);
                 }
                 $object->start = Binary::decodeVarint($input, $start);
                 break;
             case 2:
                 if ($wireType !== 0) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 0.', $number);
                 }
                 $object->end = Binary::decodeVarint($input, $start);
                 break;
             default:
                 switch ($wireType) {
                     case 0:
                         Binary::decodeVarint($input, $start);
                         break;
                     case 1:
                         $start += 8;
                         break;
                     case 2:
                         $start += Binary::decodeVarint($input, $start);
                         break;
                     case 5:
                         $start += 4;
                         break;
                     default:
                         throw new ProtobufException('Unexpected wire type ' . $wireType . '.', $number);
                 }
         }
     }
     return $object;
 }
Esempio n. 2
0
 /**
  * Creates \Google\Protobuf\UninterpretedOption\NamePart object from serialized Protocol Buffers message.
  *
  * @param string $input
  * @param NamePart $object
  * @param int $start
  * @param int $end
  *
  * @throws \Exception
  *
  * @return NamePart
  */
 public static function fromProtobuf($input, $object = NULL, &$start = 0, $end = NULL)
 {
     if ($object === null) {
         $object = new NamePart();
     }
     if ($end === null) {
         $end = strlen($input);
     }
     while ($start < $end) {
         $tag = Binary::decodeVarint($input, $start);
         $wireType = $tag & 0x7;
         $number = $tag >> 3;
         switch ($number) {
             case 1:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->namePart = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 2:
                 if ($wireType !== 0) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 0.', $number);
                 }
                 $object->isExtension = (bool) Binary::decodeVarint($input, $start);
                 break;
             default:
                 switch ($wireType) {
                     case 0:
                         Binary::decodeVarint($input, $start);
                         break;
                     case 1:
                         $start += 8;
                         break;
                     case 2:
                         $start += Binary::decodeVarint($input, $start);
                         break;
                     case 5:
                         $start += 4;
                         break;
                     default:
                         throw new ProtobufException('Unexpected wire type ' . $wireType . '.', $number);
                 }
         }
     }
     return $object;
 }
Esempio n. 3
0
 /**
  * Creates \Google\Protobuf\FileDescriptorSet object from serialized Protocol Buffers message.
  *
  * @param string $input
  * @param FileDescriptorSet $object
  * @param int $start
  * @param int $end
  *
  * @throws \Exception
  *
  * @return FileDescriptorSet
  */
 public static function fromProtobuf($input, $object = NULL, &$start = 0, $end = NULL)
 {
     if ($object === null) {
         $object = new FileDescriptorSet();
     }
     if ($end === null) {
         $end = strlen($input);
     }
     while ($start < $end) {
         $tag = Binary::decodeVarint($input, $start);
         $wireType = $tag & 0x7;
         $number = $tag >> 3;
         switch ($number) {
             case 1:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->file) && is_array($object->file))) {
                     $object->file = array();
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->file[] = FileDescriptorProtoMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             default:
                 switch ($wireType) {
                     case 0:
                         Binary::decodeVarint($input, $start);
                         break;
                     case 1:
                         $start += 8;
                         break;
                     case 2:
                         $start += Binary::decodeVarint($input, $start);
                         break;
                     case 5:
                         $start += 4;
                         break;
                     default:
                         throw new ProtobufException('Unexpected wire type ' . $wireType . '.', $number);
                 }
         }
     }
     return $object;
 }
 /**
  * Creates \Google\Protobuf\FileDescriptorProto object from serialized Protocol Buffers message.
  *
  * @param string $input
  * @param FileDescriptorProto $object
  * @param int $start
  * @param int $end
  *
  * @throws \Exception
  *
  * @return FileDescriptorProto
  */
 public static function fromProtobuf($input, $object = NULL, &$start = 0, $end = NULL)
 {
     if ($object === null) {
         $object = new FileDescriptorProto();
     }
     if ($end === null) {
         $end = strlen($input);
     }
     while ($start < $end) {
         $tag = Binary::decodeVarint($input, $start);
         $wireType = $tag & 0x7;
         $number = $tag >> 3;
         switch ($number) {
             case 1:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->name = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 2:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->package = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 3:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->dependency) && is_array($object->dependency))) {
                     $object->dependency = array();
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->dependency[] = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 10:
                 if ($wireType !== 0) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 0.', $number);
                 }
                 if (!(isset($object->publicDependency) && is_array($object->publicDependency))) {
                     $object->publicDependency = array();
                 }
                 $object->publicDependency[] = Binary::decodeVarint($input, $start);
                 break;
             case 11:
                 if ($wireType !== 0) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 0.', $number);
                 }
                 if (!(isset($object->weakDependency) && is_array($object->weakDependency))) {
                     $object->weakDependency = array();
                 }
                 $object->weakDependency[] = Binary::decodeVarint($input, $start);
                 break;
             case 4:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->messageType) && is_array($object->messageType))) {
                     $object->messageType = array();
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->messageType[] = DescriptorProtoMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 5:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->enumType) && is_array($object->enumType))) {
                     $object->enumType = array();
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->enumType[] = EnumDescriptorProtoMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 6:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->service) && is_array($object->service))) {
                     $object->service = array();
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->service[] = ServiceDescriptorProtoMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 7:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->extension) && is_array($object->extension))) {
                     $object->extension = array();
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->extension[] = FieldDescriptorProtoMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 8:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->options = FileOptionsMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 9:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->sourceCodeInfo = SourceCodeInfoMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 12:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->syntax = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             default:
                 switch ($wireType) {
                     case 0:
                         Binary::decodeVarint($input, $start);
                         break;
                     case 1:
                         $start += 8;
                         break;
                     case 2:
                         $start += Binary::decodeVarint($input, $start);
                         break;
                     case 5:
                         $start += 4;
                         break;
                     default:
                         throw new ProtobufException('Unexpected wire type ' . $wireType . '.', $number);
                 }
         }
     }
     return $object;
 }
 /**
  * Creates \Skrz\Meta\Fixtures\Protobuf\ClassWithFixed64Property object from serialized Protocol Buffers message.
  *
  * @param string $input
  * @param ClassWithFixed64Property $object
  * @param int $start
  * @param int $end
  *
  * @throws \Exception
  *
  * @return ClassWithFixed64Property
  */
 public static function fromProtobuf($input, $object = NULL, &$start = 0, $end = NULL)
 {
     if ($object === null) {
         $object = new ClassWithFixed64Property();
     }
     if ($end === null) {
         $end = strlen($input);
     }
     while ($start < $end) {
         $tag = Binary::decodeVarint($input, $start);
         $wireType = $tag & 0x7;
         $number = $tag >> 3;
         switch ($number) {
             case 1:
                 if ($wireType !== 1) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 1.', $number);
                 }
                 $expectedStart = $start + 8;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->x = Binary::decodeUint64($input, $start);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             default:
                 switch ($wireType) {
                     case 0:
                         Binary::decodeVarint($input, $start);
                         break;
                     case 1:
                         $start += 8;
                         break;
                     case 2:
                         $start += Binary::decodeVarint($input, $start);
                         break;
                     case 5:
                         $start += 4;
                         break;
                     default:
                         throw new ProtobufException('Unexpected wire type ' . $wireType . '.', $number);
                 }
         }
     }
     return $object;
 }
 /**
  * Creates \Google\Protobuf\FieldDescriptorProto object from serialized Protocol Buffers message.
  *
  * @param string $input
  * @param FieldDescriptorProto $object
  * @param int $start
  * @param int $end
  *
  * @throws \Exception
  *
  * @return FieldDescriptorProto
  */
 public static function fromProtobuf($input, $object = NULL, &$start = 0, $end = NULL)
 {
     if ($object === null) {
         $object = new FieldDescriptorProto();
     }
     if ($end === null) {
         $end = strlen($input);
     }
     while ($start < $end) {
         $tag = Binary::decodeVarint($input, $start);
         $wireType = $tag & 0x7;
         $number = $tag >> 3;
         switch ($number) {
             case 1:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->name = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 3:
                 if ($wireType !== 0) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 0.', $number);
                 }
                 $object->number = Binary::decodeVarint($input, $start);
                 break;
             case 4:
                 if ($wireType !== 0) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 0.', $number);
                 }
                 $object->label = Binary::decodeVarint($input, $start);
                 break;
             case 5:
                 if ($wireType !== 0) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 0.', $number);
                 }
                 $object->type = Binary::decodeVarint($input, $start);
                 break;
             case 6:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->typeName = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 2:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->extendee = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 7:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->defaultValue = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 9:
                 if ($wireType !== 0) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 0.', $number);
                 }
                 $object->oneofIndex = Binary::decodeVarint($input, $start);
                 break;
             case 10:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->jsonName = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 8:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->options = FieldOptionsMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             default:
                 switch ($wireType) {
                     case 0:
                         Binary::decodeVarint($input, $start);
                         break;
                     case 1:
                         $start += 8;
                         break;
                     case 2:
                         $start += Binary::decodeVarint($input, $start);
                         break;
                     case 5:
                         $start += 4;
                         break;
                     default:
                         throw new ProtobufException('Unexpected wire type ' . $wireType . '.', $number);
                 }
         }
     }
     return $object;
 }
 /**
  * Creates \Google\Protobuf\UninterpretedOption object from serialized Protocol Buffers message.
  *
  * @param string $input
  * @param UninterpretedOption $object
  * @param int $start
  * @param int $end
  *
  * @throws \Exception
  *
  * @return UninterpretedOption
  */
 public static function fromProtobuf($input, $object = NULL, &$start = 0, $end = NULL)
 {
     if ($object === null) {
         $object = new UninterpretedOption();
     }
     if ($end === null) {
         $end = strlen($input);
     }
     while ($start < $end) {
         $tag = Binary::decodeVarint($input, $start);
         $wireType = $tag & 0x7;
         $number = $tag >> 3;
         switch ($number) {
             case 2:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->name) && is_array($object->name))) {
                     $object->name = array();
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->name[] = NamePartMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 3:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->identifierValue = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 4:
                 if ($wireType !== 0) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 0.', $number);
                 }
                 $object->positiveIntValue = Binary::decodeVarint($input, $start);
                 break;
             case 5:
                 if ($wireType !== 0) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 0.', $number);
                 }
                 $object->negativeIntValue = Binary::decodeVarint($input, $start);
                 break;
             case 6:
                 if ($wireType !== 1) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 1.', $number);
                 }
                 $expectedStart = $start + 8;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->doubleValue = Binary::decodeDouble($input, $start);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 7:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->stringValue = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 8:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->aggregateValue = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             default:
                 switch ($wireType) {
                     case 0:
                         Binary::decodeVarint($input, $start);
                         break;
                     case 1:
                         $start += 8;
                         break;
                     case 2:
                         $start += Binary::decodeVarint($input, $start);
                         break;
                     case 5:
                         $start += 4;
                         break;
                     default:
                         throw new ProtobufException('Unexpected wire type ' . $wireType . '.', $number);
                 }
         }
     }
     return $object;
 }
Esempio n. 8
0
 /**
  * Creates \Google\Protobuf\DescriptorProto object from serialized Protocol Buffers message.
  *
  * @param string $input
  * @param DescriptorProto $object
  * @param int $start
  * @param int $end
  *
  * @throws \Exception
  *
  * @return DescriptorProto
  */
 public static function fromProtobuf($input, $object = NULL, &$start = 0, $end = NULL)
 {
     if ($object === null) {
         $object = new DescriptorProto();
     }
     if ($end === null) {
         $end = strlen($input);
     }
     while ($start < $end) {
         $tag = Binary::decodeVarint($input, $start);
         $wireType = $tag & 0x7;
         $number = $tag >> 3;
         switch ($number) {
             case 1:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->name = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 2:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->field) && is_array($object->field))) {
                     $object->field = array();
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->field[] = FieldDescriptorProtoMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 6:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->extension) && is_array($object->extension))) {
                     $object->extension = array();
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->extension[] = FieldDescriptorProtoMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 3:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->nestedType) && is_array($object->nestedType))) {
                     $object->nestedType = array();
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->nestedType[] = DescriptorProtoMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 4:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->enumType) && is_array($object->enumType))) {
                     $object->enumType = array();
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->enumType[] = EnumDescriptorProtoMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 5:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->extensionRange) && is_array($object->extensionRange))) {
                     $object->extensionRange = array();
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->extensionRange[] = ExtensionRangeMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 8:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->oneofDecl) && is_array($object->oneofDecl))) {
                     $object->oneofDecl = array();
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->oneofDecl[] = OneofDescriptorProtoMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 7:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->options = MessageOptionsMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 9:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->reservedRange) && is_array($object->reservedRange))) {
                     $object->reservedRange = array();
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->reservedRange[] = ReservedRangeMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 10:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->reservedName) && is_array($object->reservedName))) {
                     $object->reservedName = array();
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->reservedName[] = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             default:
                 switch ($wireType) {
                     case 0:
                         Binary::decodeVarint($input, $start);
                         break;
                     case 1:
                         $start += 8;
                         break;
                     case 2:
                         $start += Binary::decodeVarint($input, $start);
                         break;
                     case 5:
                         $start += 4;
                         break;
                     default:
                         throw new ProtobufException('Unexpected wire type ' . $wireType . '.', $number);
                 }
         }
     }
     return $object;
 }
 /**
  * Creates \Google\Protobuf\MethodDescriptorProto object from serialized Protocol Buffers message.
  *
  * @param string $input
  * @param MethodDescriptorProto $object
  * @param int $start
  * @param int $end
  *
  * @throws \Exception
  *
  * @return MethodDescriptorProto
  */
 public static function fromProtobuf($input, $object = NULL, &$start = 0, $end = NULL)
 {
     if ($object === null) {
         $object = new MethodDescriptorProto();
     }
     if ($end === null) {
         $end = strlen($input);
     }
     while ($start < $end) {
         $tag = Binary::decodeVarint($input, $start);
         $wireType = $tag & 0x7;
         $number = $tag >> 3;
         switch ($number) {
             case 1:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->name = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 2:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->inputType = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 3:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->outputType = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 4:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->options = MethodOptionsMeta::fromProtobuf($input, null, $start, $start + $length);
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 5:
                 if ($wireType !== 0) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 0.', $number);
                 }
                 $object->clientStreaming = (bool) Binary::decodeVarint($input, $start);
                 break;
             case 6:
                 if ($wireType !== 0) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 0.', $number);
                 }
                 $object->serverStreaming = (bool) Binary::decodeVarint($input, $start);
                 break;
             default:
                 switch ($wireType) {
                     case 0:
                         Binary::decodeVarint($input, $start);
                         break;
                     case 1:
                         $start += 8;
                         break;
                     case 2:
                         $start += Binary::decodeVarint($input, $start);
                         break;
                     case 5:
                         $start += 4;
                         break;
                     default:
                         throw new ProtobufException('Unexpected wire type ' . $wireType . '.', $number);
                 }
         }
     }
     return $object;
 }
Esempio n. 10
0
 /**
  * Creates \Google\Protobuf\SourceCodeInfo\Location object from serialized Protocol Buffers message.
  *
  * @param string $input
  * @param Location $object
  * @param int $start
  * @param int $end
  *
  * @throws \Exception
  *
  * @return Location
  */
 public static function fromProtobuf($input, $object = NULL, &$start = 0, $end = NULL)
 {
     if ($object === null) {
         $object = new Location();
     }
     if ($end === null) {
         $end = strlen($input);
     }
     while ($start < $end) {
         $tag = Binary::decodeVarint($input, $start);
         $wireType = $tag & 0x7;
         $number = $tag >> 3;
         switch ($number) {
             case 1:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->path) && is_array($object->path))) {
                     $object->path = array();
                 }
                 $packedLength = Binary::decodeVarint($input, $start);
                 $expectedPacked = $start + $packedLength;
                 if ($expectedPacked > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 while ($start < $expectedPacked) {
                     $object->path[] = Binary::decodeVarint($input, $start);
                 }
                 if ($start !== $expectedPacked) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedPacked . ', got ' . $start . '.', $number);
                 }
                 break;
             case 2:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->span) && is_array($object->span))) {
                     $object->span = array();
                 }
                 $packedLength = Binary::decodeVarint($input, $start);
                 $expectedPacked = $start + $packedLength;
                 if ($expectedPacked > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 while ($start < $expectedPacked) {
                     $object->span[] = Binary::decodeVarint($input, $start);
                 }
                 if ($start !== $expectedPacked) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedPacked . ', got ' . $start . '.', $number);
                 }
                 break;
             case 3:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->leadingComments = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 4:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->trailingComments = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             case 6:
                 if ($wireType !== 2) {
                     throw new ProtobufException('Unexpected wire type ' . $wireType . ', expected 2.', $number);
                 }
                 if (!(isset($object->leadingDetachedComments) && is_array($object->leadingDetachedComments))) {
                     $object->leadingDetachedComments = array();
                 }
                 $length = Binary::decodeVarint($input, $start);
                 $expectedStart = $start + $length;
                 if ($expectedStart > $end) {
                     throw new ProtobufException('Not enough data.');
                 }
                 $object->leadingDetachedComments[] = substr($input, $start, $length);
                 $start += $length;
                 if ($start !== $expectedStart) {
                     throw new ProtobufException('Unexpected start. Expected ' . $expectedStart . ', got ' . $start . '.', $number);
                 }
                 break;
             default:
                 switch ($wireType) {
                     case 0:
                         Binary::decodeVarint($input, $start);
                         break;
                     case 1:
                         $start += 8;
                         break;
                     case 2:
                         $start += Binary::decodeVarint($input, $start);
                         break;
                     case 5:
                         $start += 4;
                         break;
                     default:
                         throw new ProtobufException('Unexpected wire type ' . $wireType . '.', $number);
                 }
         }
     }
     return $object;
 }