Exemple #1
0
        public static RemotingResponse ParseResponse(byte[] data)
        {
            var srcOffset = 0;

            var requestSequence      = ByteUtil.DecodeLong(data, srcOffset, out srcOffset);
            var requestCode          = ByteUtil.DecodeShort(data, srcOffset, out srcOffset);
            var requestType          = ByteUtil.DecodeShort(data, srcOffset, out srcOffset);
            var requestTime          = ByteUtil.DecodeDateTime(data, srcOffset, out srcOffset);
            var requestHeaderLength  = ByteUtil.DecodeInt(data, srcOffset, out srcOffset);
            var requestHeader        = HeaderUtil.DecodeHeader(data, srcOffset, out srcOffset);
            var responseCode         = ByteUtil.DecodeShort(data, srcOffset, out srcOffset);
            var responseTime         = ByteUtil.DecodeDateTime(data, srcOffset, out srcOffset);
            var responseHeaderLength = ByteUtil.DecodeInt(data, srcOffset, out srcOffset);
            var responseHeader       = HeaderUtil.DecodeHeader(data, srcOffset, out srcOffset);

            var responseBodyLength = data.Length - srcOffset;
            var responseBody       = new byte[responseBodyLength];

            Buffer.BlockCopy(data, srcOffset, responseBody, 0, responseBodyLength);

            return(new RemotingResponse(
                       requestType,
                       requestCode,
                       requestSequence,
                       requestTime,
                       responseCode,
                       responseBody,
                       responseTime,
                       requestHeader,
                       responseHeader));
        }
Exemple #2
0
        public static byte[] BuildResponseMessage(RemotingResponse response)
        {
            var requestSequenceBytes     = BitConverter.GetBytes(response.RequestSequence);
            var requestCodeBytes         = BitConverter.GetBytes(response.RequestCode);
            var requestTypeBytes         = BitConverter.GetBytes(response.RequestType);
            var requestTimeBytes         = ByteUtil.EncodeDateTime(response.RequestTime);
            var requestHeaderBytes       = HeaderUtil.EncodeHeader(response.RequestHeader);
            var requestHeaderLengthBytes = BitConverter.GetBytes(requestHeaderBytes.Length);

            var responseCodeBytes         = BitConverter.GetBytes(response.ResponseCode);
            var responseTimeBytes         = ByteUtil.EncodeDateTime(response.ResponseTime);
            var responseHeaderBytes       = HeaderUtil.EncodeHeader(response.ResponseHeader);
            var responseHeaderLengthBytes = BitConverter.GetBytes(requestHeaderBytes.Length);

            return(ByteUtil.Combine(
                       requestSequenceBytes,
                       requestCodeBytes,
                       requestTypeBytes,
                       requestTimeBytes,
                       requestHeaderLengthBytes,
                       requestHeaderBytes,
                       responseCodeBytes,
                       responseTimeBytes,
                       responseHeaderLengthBytes,
                       responseHeaderBytes,
                       response.ResponseBody));
        }
Exemple #3
0
        public static RemotingServerMessage ParseRemotingServerMessage(byte[] data)
        {
            var srcOffset = 0;

            var id           = ByteUtil.DecodeString(data, srcOffset, out srcOffset);
            var type         = ByteUtil.DecodeShort(data, srcOffset, out srcOffset);
            var code         = ByteUtil.DecodeShort(data, srcOffset, out srcOffset);
            var createdTime  = ByteUtil.DecodeDateTime(data, srcOffset, out srcOffset);
            var headerLength = ByteUtil.DecodeInt(data, srcOffset, out srcOffset);
            var header       = HeaderUtil.DecodeHeader(data, srcOffset, out srcOffset);
            var bodyLength   = data.Length - srcOffset;
            var body         = new byte[bodyLength];

            Buffer.BlockCopy(data, srcOffset, body, 0, bodyLength);

            return(new RemotingServerMessage(type, id, code, body, createdTime, header));
        }
Exemple #4
0
        public static RemotingRequest ParseRequest(byte[] data)
        {
            var srcOffset = 0;

            var id           = ByteUtil.DecodeString(data, srcOffset, out srcOffset);
            var sequence     = ByteUtil.DecodeLong(data, srcOffset, out srcOffset);
            var code         = ByteUtil.DecodeShort(data, srcOffset, out srcOffset);
            var type         = ByteUtil.DecodeShort(data, srcOffset, out srcOffset);
            var createdTime  = ByteUtil.DecodeDateTime(data, srcOffset, out srcOffset);
            var headerLength = ByteUtil.DecodeInt(data, srcOffset, out srcOffset);
            var header       = HeaderUtil.DecodeHeader(data, srcOffset, out srcOffset);
            var bodyLength   = data.Length - srcOffset;
            var body         = new byte[bodyLength];

            Buffer.BlockCopy(data, srcOffset, body, 0, bodyLength);

            return(new RemotingRequest(id, code, sequence, body, createdTime, header)
            {
                Type = type
            });
        }
Exemple #5
0
        public static byte[] BuildRemotingServerMessage(RemotingServerMessage message)
        {
            byte[] IdBytes;
            byte[] IdLengthBytes;
            ByteUtil.EncodeString(message.Id, out IdLengthBytes, out IdBytes);

            var typeBytes         = BitConverter.GetBytes(message.Type);
            var codeBytes         = BitConverter.GetBytes(message.Code);
            var createdTimeBytes  = ByteUtil.EncodeDateTime(message.CreatedTime);
            var headerBytes       = HeaderUtil.EncodeHeader(message.Header);
            var headerLengthBytes = BitConverter.GetBytes(headerBytes.Length);

            return(ByteUtil.Combine(
                       IdLengthBytes,
                       IdBytes,
                       typeBytes,
                       codeBytes,
                       createdTimeBytes,
                       headerLengthBytes,
                       headerBytes,
                       message.Body));
        }
Exemple #6
0
        public static byte[] BuildRequestMessage(RemotingRequest request)
        {
            byte[] IdBytes;
            byte[] IdLengthBytes;
            ByteUtil.EncodeString(request.Id, out IdLengthBytes, out IdBytes);

            var sequenceBytes     = BitConverter.GetBytes(request.Sequence);
            var codeBytes         = BitConverter.GetBytes(request.Code);
            var typeBytes         = BitConverter.GetBytes(request.Type);
            var createdTimeBytes  = ByteUtil.EncodeDateTime(request.CreatedTime);
            var headerBytes       = HeaderUtil.EncodeHeader(request.Header);
            var headerLengthBytes = BitConverter.GetBytes(headerBytes.Length);

            return(ByteUtil.Combine(
                       IdLengthBytes,
                       IdBytes,
                       sequenceBytes,
                       codeBytes,
                       typeBytes,
                       createdTimeBytes,
                       headerLengthBytes,
                       headerBytes,
                       request.Body));
        }