public function to_avro()
  {
    $avro = array("protocol" => $this->name, "namespace" => $this->namespace);
    
    if (!is_null($this->doc))
      $avro["doc"] = $this->doc;
    
    $types = array();
    $avro["types"] = $this->schemata->to_avro();
    
    $messages = array();
    foreach ($this->messages as $name => $msg)
      $messages[$name] = $msg->to_avro();
    $avro["messages"] = $messages;
    
    return $avro;
  }