/** * Creates \Skrz\Bundle\BunnyBundle\Tests\Fixtures\Message object from serialized Protocol Buffers message. * * @param string $input * @param Message $object * @param int $start * @param int $end * * @throws \Exception * * @return Message */ public static function fromProtobuf($input, $object = NULL, &$start = 0, $end = NULL) { if ($object === null) { $object = new Message(); } 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->intValue = Binary::decodeVarint($input, $start); break; case 2: 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->floatValue = Binary::decodeDouble($input, $start); 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->stringValue = 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\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; }