Example #1
0
        private Response Send(Request request, bool responseAvailable)
        {
            using (var memoryStream = new BinaryMemoryStream())
            {
                memoryStream.Writer.Write((short) request.RequestType);
                request.WriteToStream(memoryStream);
                var data = memoryStream.ToArray();
                _socket.Send(data);
            }

            if (!responseAvailable)
                return null;

            var result = _socket.Recv();

            using (var stream = new BinaryMemoryStream(result))
            {
                var responseType = (ResponseType) stream.Reader.ReadInt16();

                switch (responseType)
                {
                    case ResponseType.BrokerInfoResponse:
                        return BrokerInfoResponse.ReadFromStream(stream);
                    case ResponseType.FetchResponse:
                        return FetchResponse.ReadFromStream(stream);
                    case ResponseType.MultiFetchResponse:
                        return MultiFetchResponse.ReadFromStream(stream);
                }

                return null;
            }
        }
Example #2
0
 public Response Send(Request request)
 {
     return Send(request, true);
 }
Example #3
0
 public void Push(Request request)
 {
     Send(request, false);
 }