Esempio n. 1
0
        public void TestCodec()
        {
            Person person = new Person
            {
                Name = "张宏伟",
                Age  = 18
            };
            TransportMessage transportMessage = new TransportMessage
            {
                Id          = "1",
                ContentType = "Person",
                Content     = person
            };
            MessagePackTransportMessageCodecFactory factory = new MessagePackTransportMessageCodecFactory();
            ITransportMessageEncoder encoder = factory.GetEncoder();
            ITransportMessageDecoder decoder = factory.GetDecoder();

            byte[]           vs      = encoder.Encode(transportMessage);
            TransportMessage message = decoder.Decode(vs);

            Assert.AreEqual(message.Id, "1");
            Assert.AreEqual(message.ContentType, "Person");
            Assert.AreEqual(((object[])message.Content)[0].ToString(), "张宏伟");
            Assert.AreEqual(((object[])message.Content)[1].ToString(), "18");
        }
Esempio n. 2
0
        protected byte [] GetByteBuffer(TransportMessage message)
        {
            var data = _transportMessageEncoder.Encode(message);

            //var buffer = Unpooled.Buffer(data.Length, data.Length);
            return(data);
        }
Esempio n. 3
0
        protected IByteBuffer GetByteBuffer(TransportMessage message)
        {
            var data = _transportMessageEncoder.Encode(message);

            //var buffer = PooledByteBufferAllocator.Default.Buffer();
            return(Unpooled.WrappedBuffer(data));
        }
Esempio n. 4
0
        protected IByteBuffer GetByteBuffer(TransportMessage message)
        {
            var data   = _transportMessageEncoder.Encode(message);
            var buffer = Unpooled.Buffer(data.Length, data.Length);

            return(buffer.WriteBytes(data));
        }
Esempio n. 5
0
        public Task OnReceive(IChannelHandlerContext context, object message)
        {
            var data = (TransportMessage)message;

            var result = _invoker.InvokerAsync(data).Result;

            if (result == null)
            {
                throw new RpcRemoteException("本地服务调用失败", null);
            }
            var transportMessage = TransportMessage.CreateInvokeResultMessage(data.Id, result);
            //var transportMessage = new TransportMessage(result);
            var byteMessage = _encoder.Encode(transportMessage);
            var buffer      = Unpooled.Buffer(byteMessage.Length, byteMessage.Length);

            buffer.WriteBytes(byteMessage);
            return(context.WriteAndFlushAsync(buffer));
        }
Esempio n. 6
0
 protected byte[] GetBinary(TransportMessage message)
 {
     return(_transportMessageEncoder.Encode(message));
 }
Esempio n. 7
0
        protected byte[] GetByteBuffer(TransportMessage message)
        {
            var data = _transportMessageEncoder.Encode(message);

            return(data);
        }