예제 #1
0
 public function to_avro()
 {
     $avro = array();
     if (!is_null($this->doc)) {
         $avro["doc"] = $this->doc;
     }
     $avro["request"] = $this->request->to_avro();
     if ($this->is_one_way()) {
         $avro["response"] = "null";
         $avro["one-way"] = true;
     } else {
         if (!is_null($this->response)) {
             $response_type = $this->response->type();
             if (AvroSchema::is_named_type($response_type)) {
                 $response_type = $this->response->qualified_name();
             } else {
                 $response_type = $this->response->to_avro();
             }
             $avro["response"] = $response_type;
         } else {
             throw new AvroProtocolParseException("Message '" . $this->name . "' has no declared response but is not a one-way message.");
         }
         if (!is_null($this->errors)) {
             $avro["errors"] = array();
             foreach ($this->errors->schemas() as $error) {
                 $error_type = $error->type();
                 if (AvroSchema::is_named_type($error_type)) {
                     $error_type = $error->qualified_name();
                 }
                 $avro["errors"][] = $error_type;
             }
             array_shift($avro["errors"]);
             if (count($avro["errors"]) == 0) {
                 unset($avro["errors"]);
             }
         }
     }
     return $avro;
 }