public function readMessage($stream)
 {
     Log::log(LoggingConstants::DEBUG, "Called");
     Log::log(LoggingConstants::INFO, "Content-Length:" . strlen($stream));
     $reader = new FlashorbBinaryReader($stream);
     $version = $reader->readUnsignedShort();
     $headersCount = $reader->readUnsignedShort();
     Log::log(LoggingConstants::DEBUG, "Version:{$version}, headers count: {$headersCount}");
     $headers = array();
     for ($i = 0; $i < $headersCount; $i++) {
         Log::log(LoggingConstants::DEBUG, "Reading header {$i}");
         $headers[$i] = $this->readHeader($reader);
         Log::log(LoggingConstants::DEBUG, "Header info:" . $headers[$i]->toString());
     }
     $bodyCount = $reader->readUnsignedShort();
     Log::log(LoggingConstants::DEBUG, "Body count: {$bodyCount}");
     $body = array();
     for ($i = 0; $i < $bodyCount; $i++) {
         Log::log(LoggingConstants::DEBUG, "Reading body {$i}");
         $body[$i] = $this->readBodyPart($reader);
     }
     $request = new Request($version, $headers, $body);
     $request->setFormatter(3 == $version ? new AmfV3Formatter() : new AmfFormatter());
     return $request;
 }