コード例 #1
0
ファイル: Message.php プロジェクト: slavanap/protobuf
 /**
  * @ignore
  */
 private function parseFieldFromStream($tag, $input, $field)
 {
     $value = null;
     $field_type = $field->getType();
     $value_format = GPBWire::UNKNOWN;
     if (GPBWire::getTagWireType($tag) === GPBWire::getWireType($field_type)) {
         $value_format = GPBWire::NORMAL_FORMAT;
     } elseif ($field->isPackable() && GPBWire::getTagWireType($tag) === GPBWire::WIRETYPE_LENGTH_DELIMITED) {
         $value_format = GPBWire::PACKED_FORMAT;
     }
     if ($value_format === GPBWire::NORMAL_FORMAT) {
         if (!self::parseFieldFromStreamNoTag($input, $field, $value)) {
             return false;
         }
     } elseif ($value_format === GPBWire::PACKED_FORMAT) {
         $length = 0;
         if (!GPBWire::readInt32($input, $length)) {
             return false;
         }
         $limit = $input->pushLimit($length);
         $getter = $field->getGetter();
         while ($input->bytesUntilLimit() > 0) {
             if (!self::parseFieldFromStreamNoTag($input, $field, $value)) {
                 return false;
             }
             $this->{$getter}()[] = $value;
         }
         $input->popLimit($limit);
         return true;
     } else {
         return false;
     }
     if ($field->isMap()) {
         $getter = $field->getGetter();
         $this->{$getter}()[$value->getKey()] = $value->getValue();
     } else {
         if ($field->isRepeated()) {
             $getter = $field->getGetter();
             $this->{$getter}()[] = $value;
         } else {
             $setter = $field->getSetter();
             $this->{$setter}($value);
         }
     }
     return true;
 }