コード例 #1
0
ファイル: RequestParser.cs プロジェクト: Georotzen/.NET-SDK-1
    public Request readMessage(Stream input)
    {
      FlashorbBinaryReader reader = new FlashorbBinaryReader(input);

      try
      {
        if (Log.isLogging(LoggingConstants.DEBUG))
          Log.log(LoggingConstants.DEBUG, "MessageReader:: parsing stream");

        int version = reader.ReadUnsignedShort();
        int totalHeaders = reader.ReadUnsignedShort();

        if (Log.isLogging(LoggingConstants.DEBUG))
          Log.log(LoggingConstants.DEBUG, "MessageReader:: parsing message - version: " + version + " totalHeaders: " + totalHeaders);

        Header[] headers = new Header[totalHeaders];

        for (int i = 0; i < totalHeaders; i++)
          headers[i] = readHeader(reader);

        int totalBodyParts = reader.ReadUnsignedShort();

        if (Log.isLogging(LoggingConstants.DEBUG))
          Log.log(LoggingConstants.DEBUG, "MessageReader:: Total body parts: " + totalBodyParts);

        Body[] bodies = new Body[totalBodyParts];

        for (int i = 0; i < totalBodyParts; i++)
          bodies[i] = readBodyPart(reader);

        if (Log.isLogging(LoggingConstants.DEBUG))
          Log.log(LoggingConstants.DEBUG, "MessageReader:: returning AMFMessage");

        Request request = new Request(version, headers, bodies);
        request.SetFormatter(version == 3 ? (IProtocolFormatter)new AmfV3Formatter() : (IProtocolFormatter)new AmfFormatter());
        return request;
      }
      catch (Exception exception)
      {
        if (Log.isLogging(LoggingConstants.EXCEPTION))
          Log.log(LoggingConstants.EXCEPTION, "Exception: " + exception.Message + " StackTrace: " + exception.StackTrace);
        return null;
      }
    }