protected function _describe(Protobuf\Descriptor $descriptor) { $name = $descriptor->getName(); if (isset($this->_resources[$name])) { return $this->_resources[$name]; } // Create the message descriptor resource $res = \protobuf_desc_message($name); // Add the resource immediately in the dictionary to support cyclic references $this->_resources[$name] = $res; $lazy = $this->getOption('lazy'); // Iterate over all the fields to setup the message foreach ($descriptor->getFields() as $field) { $type = $field->getType(); // Nested messages need to be populated first if ($type === Protobuf\Protobuf::TYPE_MESSAGE) { // When in lazy decoding mode we handle nested messages as binary fields if ($lazy) { $type = Protobuf\Protobuf::TYPE_BYTES; } else { // Try to obtain the message descriptor resource for this field $descr = Protobuf\Protobuf::getRegistry()->getDescriptor($field->getReference()); if (!$descr) { throw new \RuntimeException('Unable to find a descriptor for message "' . $field->getReference() . '"'); } $nested = $this->_describe($descr); } } //printf("N: %d R: %d T: %d Name: %s P: %d\n", $field->getNumber(), $field->getRule(), $type, $field->getName(), $field->isPacked() ? PROTOBUF_FLAG_PACKED : 0); // Append the field definition to the message \protobuf_desc_field($res, $field->getNumber(), $field->getRule(), $type, $field->getName(), $field->isPacked() ? PROTOBUF_FLAG_PACKED : 0, $type === Protobuf\Protobuf::TYPE_MESSAGE ? $nested : NULL); } return $res; }
public function offsetUnset($offset) { if (is_numeric($offset)) { $field = $this->_descriptor->getField($offset); if (!$field) { trigger_error("Protobuf message " . $this->_descriptor->getName() . " doesn't have any field with a tag number of {$offset}", E_USER_NOTICE); return; } if ($field->isExtension()) { $data =& $this->_extensions; } else { $data =& $this->_values; } if (isset($data[$field->name])) { unset($data[$field->name]); } } else { $this->clearExtension($offset); } }