示例#1
0
        private IByteBuffer GetBuffer(IChannel channel, TMessage message)
        {
            var           buff   = channel.Allocator.Buffer(message.Length);
            IBufferWriter writer = NettyBufferManager.CreateBufferWriter(buff);

            this._codecs.Encode(message, writer);
            return(buff);
        }
示例#2
0
        protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List <object> output)
        {
            IBufferReader reader  = NettyBufferManager.CreateBufferReader(input);
            IMessage      message = this._codecs.Decode(reader);

            if (message != null)
            {
                output.Add(message);
            }
        }
        /// <summary>
        /// 发送心跳包
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public Task SendHeartbeatAsync(IChannelHandlerContext ctx, IdleStateEvent state)
        {
            //获取心跳包的打包内容
            TMessage message       = this._msgCodecs.HeartbeatMessage();
            var      heartbeatBuff = ctx.Allocator.Buffer(message.Length);
            var      bufferWritter = NettyBufferManager.CreateBufferWriter(heartbeatBuff);

            this._msgCodecs.Encode(message, bufferWritter);

            return(ctx.WriteAndFlushAsync(heartbeatBuff));
        }
示例#4
0
 public ChannelDecodeHandler(IMessageCodecs <TMessage> codecs)
 {
     this._codecs             = codecs;
     this._nettyBufferManager = new NettyBufferManager();
 }