Ejemplo n.º 1
0
 private function getFieldDescriptor($name, $label, $type, $number, $type_name = null)
 {
     $field = new FieldDescriptor();
     $field->setName($name);
     $camel_name = implode('', array_map('ucwords', explode('_', $name)));
     $field->setGetter('get' . $camel_name);
     $field->setSetter('set' . $camel_name);
     $field->setType($type);
     $field->setNumber($number);
     $field->setLabel($label);
     // At this time, the message/enum type may have not been added to pool.
     // So we use the type name as place holder and will replace it with the
     // actual descriptor in cross building.
     switch ($type) {
         case GPBType::MESSAGE:
             $field->setMessageType($type_name);
             break;
         case GPBType::ENUM:
             $field->setEnumType($type_name);
             break;
         default:
             break;
     }
     return $field;
 }
Ejemplo n.º 2
0
 public static function buildFromProto($proto)
 {
     $type_name = null;
     switch ($proto->getType()) {
         case GPBType::MESSAGE:
         case GPBType::GROUP:
         case GPBType::ENUM:
             $type_name = $proto->getTypeName();
             break;
         default:
             break;
     }
     $oneof_index = $proto->hasOneofIndex() ? $proto->getOneofIndex() : -1;
     $packed = false;
     $options = $proto->getOptions();
     if ($options !== null) {
         $packed = $options->getPacked();
     }
     return FieldDescriptor::getFieldDescriptor($proto->getName(), $proto->getLabel(), $proto->getType(), $proto->getNumber(), $oneof_index, $packed, $type_name);
 }