protected function filterValue($value, Protobuf\Field $field) { if ($value instanceof Protobuf\Message) { if ($this->isKeyValueMessage($value)) { $v = $value->getValue(); return [$value->getKey() => $v instanceof Protobuf\Message ? $this->encodeMessage($v) : $v]; } if ($value instanceof Struct) { $vals = []; foreach ($value->getFields() as $field) { $val = $this->filterValue($field->getValue(), $field->descriptor()->getFieldByName('value')); $vals[$field->getKey()] = current($val); } return $vals; } if ($value instanceof ListValue) { $vals = []; foreach ($value->getValuesList() as $val) { $vals[] = current($this->encodeMessage($val)); } return $vals; } } return parent::filterValue($value, $field); }