Beispiel #1
0
        /// <summary>解码</summary>
        /// <param name="context"></param>
        /// <param name="pk"></param>
        /// <returns></returns>
        protected override IList <Packet> Decode(IHandlerContext context, Packet pk)
        {
            var ss = context.Owner as IExtend;
            var pc = ss["Codec"] as PacketCodec;

            if (pc == null)
            {
                ss["Codec"] = pc = new PacketCodec {
                    Expire = Expire, GetLength = p => GetLength(p, Offset, Size)
                }
            }
            ;

            var pks = pc.Parse(pk);

            // 跳过头部长度
            var len = Offset + Math.Abs(Size);

            foreach (var item in pks)
            {
                item.Set(item.Data, item.Offset + len, item.Count - len);
            }

            return(pks);
        }
    }
Beispiel #2
0
        /// <summary>解码</summary>
        /// <param name="context"></param>
        /// <param name="pk"></param>
        /// <returns></returns>
        protected override IList <IMessage> Decode(IHandlerContext context, Packet pk)
        {
            var ss = context.Owner as IExtend;

            if (ss["Codec"] is not PacketCodec pc)
            {
                ss["Codec"] = pc = new PacketCodec
                {
                    GetLength = DefaultMessage.GetLength,
                    Tracer    = (context.Owner as ISocket)?.Tracer
                };
            }

            var pks  = pc.Parse(pk);
            var list = pks.Select(e =>
            {
                var msg = new DefaultMessage();
                if (!msg.Read(e))
                {
                    return(null);
                }

                return(msg as IMessage);
            }).ToList();

            return(list);
        }
Beispiel #3
0
        /// <summary>解码</summary>
        /// <param name="context"></param>
        /// <param name="pk"></param>
        /// <returns></returns>
        protected override IList <IMessage> Decode(IHandlerContext context, Packet pk)
        {
            var ss = context.Owner as IExtend;
            var pc = ss["Codec"] as PacketCodec;

            if (pc == null)
            {
                ss["Codec"] = pc = new PacketCodec {
                    GetLength = DefaultMessage.GetLength
                }
            }
            ;

            var pks  = pc.Parse(pk);
            var list = pks.Select(e =>
            {
                var msg = new DefaultMessage();
                if (!msg.Read(e))
                {
                    return(null);
                }

                return(msg as IMessage);
            }).ToList();

            return(list);
        }
Beispiel #4
0
        /// <summary>解码</summary>
        /// <param name="context"></param>
        /// <param name="pk"></param>
        /// <returns></returns>
        protected override IList <Packet> Decode(IHandlerContext context, Packet pk)
        {
            var ss = context.Owner as IExtend;

            if (ss["Codec"] is not PacketCodec pc)
            {
                ss["Codec"] = pc = new PacketCodec
                {
                    Expire    = Expire,
                    GetLength = p => GetLength(p, Offset, Size),
                    Offset    = Offset,
                    Tracer    = (context.Owner as ISocket)?.Tracer
                };
            }

            var pks = pc.Parse(pk);

            // 跳过头部长度
            var len = Offset + Math.Abs(Size);

            foreach (var item in pks)
            {
                item.Set(item.Data, item.Offset + len, item.Count - len);
            }

            return(pks);
        }
Beispiel #5
0
        /// <summary>解码</summary>
        /// <param name="context"></param>
        /// <param name="pk">包</param>
        /// <returns></returns>
        protected IList <Packet> Decode(IHandlerContext context, Packet pk)
        {
            var ss = context.Owner as IExtend;

            if (ss["Codec"] is not PacketCodec pc)
            {
                ss["Codec"] = pc = new PacketCodec {
                    MaxCache = MaxCacheDataLength, GetLength = GetLineLength
                }
            }
            ;

            return(pc.Parse(pk));
        }