protected void Send(TransmissionState state, Result result, TResponse baseResponse = null)
        {
            result = result ?? Result.Success;

            try
            {
                string data;
                var    serialize = Result.Success;
                SocketResponsePackage <TResponse, TResponseTypes> response;
                // TODO: Consider other options.
                if (result.Any(i => i.Level >= ResultIssueLevels.Fatal))
                {
                    ErrorOut(result);
                }

                if (IsFailed ||
                    (response = PackResponse(result, baseResponse)) == null ||
                    !(serialize += PayloadSerializer.Serialize(response, out data)) ||
                    !state.Send(data))
                {
                    Send(state, result + serialize);
                }
            }
            catch (Exception e)
            {
                ErrorOut(result + Result.Error(e));
            }
        }
        public string GetMessageText(Message message)
        {
            StringBuilder sb = new StringBuilder();

            using (TextWriter writer = new StringWriter(sb))
            {
                PayloadSerializer.Serialize(writer, message);
                writer.Flush();;
            }
            return(sb.ToString());
        }