/// <summary>
        /// Tries to decode the message.
        /// </summary>
        /// <param name="buffer">The buffer.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="messageType">Type of the message.</param>
        /// <param name="message">The decoded message.</param>
        /// <returns>
        /// True if message was successfully decoded; false otherwise.
        /// </returns>
        public static bool TryDecode(byte[] buffer, int offset, MessageType messageType, out TrackerMessage message)
        {
            int action;

            message = null;

            if (buffer.IsNotNullOrEmpty())
            {
                action = messageType == MessageType.Request ? Message.ReadInt(buffer, ref offset) : Message.ReadInt(buffer, ref offset);
                offset = 0;

                if (action == (int)TrackingAction.Connect)
                {
                    if (messageType == MessageType.Request)
                    {
                        ConnectMessage message2;
                        ConnectMessage.TryDecode(buffer, offset, out message2);

                        message = message2;
                    }
                    else
                    {
                        ConnectResponseMessage message2;
                        ConnectResponseMessage.TryDecode(buffer, offset, out message2);

                        message = message2;
                    }
                }
                else if (action == (int)TrackingAction.Announce)
                {
                    if (messageType == MessageType.Request)
                    {
                        AnnounceMessage message2;
                        AnnounceMessage.TryDecode(buffer, offset, out message2);

                        message = message2;
                    }
                    else
                    {
                        AnnounceResponseMessage message2;
                        AnnounceResponseMessage.TryDecode(buffer, offset, out message2);

                        message = message2;
                    }
                }
                else if (action == (int)TrackingAction.Scrape)
                {
                    if (messageType == MessageType.Request)
                    {
                        ScrapeMessage message2;
                        ScrapeMessage.TryDecode(buffer, offset, out message2);

                        message = message2;
                    }
                    else
                    {
                        ScrapeResponseMessage message2;
                        ScrapeResponseMessage.TryDecode(buffer, offset, out message2);

                        message = message2;
                    }
                }
                else if (action == (int)TrackingAction.Error)
                {
                    ErrorMessage message2;
                    ErrorMessage.TryDecode(buffer, offset, out message2);

                    message = message2;
                }
                else
                {
                    // could not decode UDP message
                }
            }

            return(message != null);
        }