Esempio n. 1
0
        /// <summary>
        /// Given a byte array describing a full message.<br/>
        /// Parses the byte array into a <see cref="MessagePart"/>.
        /// </summary>
        /// <param name="rawMessageContent">The byte array containing both headers and body of a message</param>
        /// <returns>A <see cref="MessagePart"/> which was described by the <paramref name="rawMessageContent"/> byte array</returns>
        private static MessagePart GetMessagePart(byte[] rawMessageContent)
        {
            // Find the headers and the body parts of the byte array
            MessageHeader headers;

            byte[] body;
            HeaderExtractor.ExtractHeadersAndBody(rawMessageContent, out headers, out body);

            // Create a new MessagePart from the headers and the body
            return(new MessagePart(body, headers));
        }
Esempio n. 2
0
        /// <summary>
        /// Constructs a message from a byte array.<br/>
        /// <br/>
        /// The headers are always parsed, but if <paramref name="parseBody"/> is <see langword="false"/>, the body is not parsed.
        /// </summary>
        /// <param name="rawMessageContent">The byte array which is the message contents to parse</param>
        /// <param name="parseBody">
        /// <see langword="true"/> if the body should be parsed,
        /// <see langword="false"/> if only headers should be parsed out of the <paramref name="rawMessageContent"/> byte array
        /// </param>
        /// <param name="parsingErrorHandler">(Optional) It is notifified when an error occurs while parsing something in the message.
        /// If it is not null, the handler handles the error on the specific element without stopping the message parsing process</param>
        public Message(byte[] rawMessageContent, bool parseBody)
        {
            RawMessage = rawMessageContent;

            // Find the headers and the body parts of the byte array
            MessageHeader headersTemp;

            byte[] body;
            HeaderExtractor.ExtractHeadersAndBody(rawMessageContent, out headersTemp, out body);

            // Set the Headers property
            Headers = headersTemp;

            // Should we also parse the body?
            if (parseBody)
            {
                // Parse the body into a MessagePart
                MessagePart = new MessagePart(body, Headers);
            }
        }