private IEnumerator SendRequest <TReq, TRes>(string method, TReq parameters, JsonRpcCallOutput output)
        {
            string id = (++Id).ToString();

            Request <TReq>  request  = new Request <TReq>(id, method, parameters);
            Response <TRes> response = null;

            string requestTransport = JsonUtility.ToJson(request);

            Exception error             = null;
            string    responseTransport = null;

            yield return(this.transport.Request(requestTransport, (JsonRpcTransportException err, string res) => { error = err; responseTransport = res; }));

            if (string.IsNullOrEmpty(responseTransport))
            {
                error = new JsonRpcException(ERR_MSG_EMPTY_TRANSPORT_RESPONSE);
            }

            if (error != null)
            {
                output.error = (JsonRpcException)error;
                yield break;
            }

            response = JsonUtility.FromJson <Response <TRes> >(responseTransport);
            if (response.error.code != Int32.MinValue)
            {
                output.error = (JsonRpcException)error;
                yield break;
            }

            output.result = response.result;
        }
        public IEnumerator Send()
        {
            var output = new JsonRpcCallOutput();

            yield return(this.client.Send <TReq, TRes>(this.type, this.method, this.parameters, output));

            this.error  = output.error;
            this.result = (TRes)output.result;
        }
        private IEnumerator SendNotification <TReq>(string method, TReq parameters, JsonRpcCallOutput output)
        {
            Notification <TReq> request = new Notification <TReq>(method, parameters);

            string requestTransport = JsonUtility.ToJson(request);

            Exception error = null;

            yield return(this.transport.Notification(requestTransport, (JsonRpcTransportException err) => { error = err; }));

            if (error == null)
            {
                yield break;
            }
            output.error = new JsonRpcException(error.Message);
        }
        internal IEnumerator Send <TReq, TRes>(JsonRpcCallType type, string method, TReq parameters, JsonRpcCallOutput output)
        {
            if (!this.parallelRequestsAllowed)
            {
                while (JsonRpcService.RequestInProgress)
                {
                    yield return(new WaitForEndOfFrame());
                }
            }

            JsonRpcService.RequestInProgress = true;

            if (type == JsonRpcCallType.Notification)
            {
                yield return(this.SendNotification <TReq>(method, (TReq)parameters, output));
            }
            else
            if (type == JsonRpcCallType.Request)
            {
                yield return(this.SendRequest <TReq, TRes>(method, (TReq)parameters, output));
            }

            JsonRpcService.RequestInProgress = false;
        }