public override AnalyzedPacket Filter(ref ReadOnlySequence <byte> buffer)
        {
            try
            {
                if (buffer.Length < HEADER_SIZE)
                {
                    return(null);
                }

                var woringSpan = buffer.First.Span;

                var packetTotalSize = C3SockNetUtil.FastBinaryRead.UInt16(woringSpan, 0);
                var BodySize        = (UInt16)(packetTotalSize - HEADER_SIZE);
                var ProtocolId      = C3SockNetUtil.FastBinaryRead.UInt16(woringSpan, 2);
                var PacketType      = C3SockNetUtil.FastBinaryRead.SByte(woringSpan, 4);

                if (BodySize == 0)
                {
                    var packet = new AnalyzedPacket
                    {
                        SessionUniqueId = 0,
                        PacketId        = ProtocolId,
                        Head            = null,
                        Body            = buffer.ToArray()
                    };

                    buffer = buffer.Slice(packetTotalSize);
                    return(packet);
                }
                else if (BodySize > 0 && (packetTotalSize >= buffer.Length))
                {
                    var packet = new AnalyzedPacket
                    {
                        SessionUniqueId = 0,
                        PacketId        = ProtocolId,
                        Head            = null,
                        Body            = buffer.Slice(HEADER_SIZE, BodySize).ToArray()
                    };

                    buffer = buffer.Slice(packetTotalSize);
                    return(packet);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                GLogging.Logger().LogError($"Failed to Filter {ex.ToString()}");
                return(null);
            }
        }
        public bool Configure(ServerOptions options, IServiceCollection services,
                              List <IPipelineFilterFactory> pipelineFilterFactoryList)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (pipelineFilterFactoryList == null)
            {
                throw new ArgumentNullException(nameof(pipelineFilterFactoryList));
            }


            Options            = options;
            _serviceCollection = services.AddOptions();
            _serviceProvider   = services.BuildServiceProvider();

            LoggerFactory = _serviceProvider.GetRequiredService <ILoggerFactory>();
            LoggerFactory.AddNLog();
            _logger = LoggerFactory.CreateLogger("SuperSocket");
            GLogging.SetLogger(_logger);


            var listenerFactory = _serviceProvider.GetService <IListenerFactory>();

            if (listenerFactory == null)
            {
                listenerFactory = new TcpSocketListenerFactory();
            }

            _listeners = new List <IListener>();

            var index = 0;

            foreach (var l in options.Listeners)
            {
                var listener = listenerFactory.CreateListener(l, pipelineFilterFactoryList[index]);
                listener.NewClientAccepted += OnNewClientAccept;
                _listeners.Add(listener);

                ++index;
            }

            return(_configured = true);
        }
        public override AnalyzedPacket Filter(ref ReadOnlySequence <byte> buffer)
        {
            try
            {
                ReadOnlySequence <byte> slice;
                SequencePosition        cursor;

                if (!buffer.TrySliceTo(CheckFunc, out slice, out cursor))
                {
                    return(null);
                }

                buffer = buffer.Slice(cursor).Slice(TerminatorLen);
                return(ResolvePackage(slice));
            }
            catch (Exception ex)
            {
                GLogging.Logger().LogError($"Failed to Filter {ex.ToString()}");
                return(null);
            }
        }