AsArraySegment() public method

public AsArraySegment ( ) : ArraySegment
return ArraySegment
        private void SendPackage(TcpPackage package, bool checkQueueSize = true)
        {
            if (IsClosed)
            {
                return;
            }

            int queueSize;
            int queueSendBytes;

            if (checkQueueSize)
            {
                if ((queueSize = _connection.SendQueueSize) > ConnectionQueueSizeThreshold)
                {
                    SendBadRequestAndClose(Guid.Empty, string.Format("Connection queue size is too large: {0}.", queueSize));
                    return;
                }
                if (_connectionPendingSendBytesThreshold > ESConsts.UnrestrictedPendingSendBytes && (queueSendBytes = _connection.PendingSendBytes) > _connectionPendingSendBytesThreshold)
                {
                    SendBadRequestAndClose(Guid.Empty, string.Format("Connection pending send bytes is too large: {0}.", queueSendBytes));
                    return;
                }
            }

            var data   = package.AsArraySegment();
            var framed = _framer.FrameData(data);

            _connection.EnqueueSend(framed);
        }
        private void SendPackage(TcpPackage package)
        {
            var data   = package.AsArraySegment();
            var framed = _framer.FrameData(data);

            _connection.EnqueueSend(framed);
        }
        public void not_authorized_with_empty_data_should_serialize_and_deserialize_correctly()
        {
            var corrId = Guid.NewGuid();
            var refPkg = new TcpPackage(TcpCommand.BadRequest, TcpFlags.None, corrId, null, null, new byte[0]);
            var bytes = refPkg.AsArraySegment();

            var pkg = TcpPackage.FromArraySegment(bytes);
            Assert.AreEqual(TcpCommand.BadRequest, pkg.Command);
            Assert.AreEqual(TcpFlags.None, pkg.Flags);
            Assert.AreEqual(corrId, pkg.CorrelationId);
            Assert.AreEqual(null, pkg.Login);
            Assert.AreEqual(null, pkg.Password);

            Assert.AreEqual(0, pkg.Data.Count);
        }
        public void authorized_with_data_should_serialize_and_deserialize_correctly()
        {
            var corrId = Guid.NewGuid();
            var refPkg = new TcpPackage(TcpCommand.BadRequest, TcpFlags.Authenticated, corrId, "login", "pa$$", new byte[] { 1, 2, 3 });
            var bytes = refPkg.AsArraySegment();

            var pkg = TcpPackage.FromArraySegment(bytes);
            Assert.AreEqual(TcpCommand.BadRequest, pkg.Command);
            Assert.AreEqual(TcpFlags.Authenticated, pkg.Flags);
            Assert.AreEqual(corrId, pkg.CorrelationId);
            Assert.AreEqual("login", pkg.Login);
            Assert.AreEqual("pa$$", pkg.Password);

            Assert.AreEqual(3, pkg.Data.Count);
            Assert.AreEqual(1, pkg.Data.Array[pkg.Data.Offset + 0]);
            Assert.AreEqual(2, pkg.Data.Array[pkg.Data.Offset + 1]);
            Assert.AreEqual(3, pkg.Data.Array[pkg.Data.Offset + 2]);
        }
        private void SendPackage(TcpPackage package, bool checkQueueSize = true)
        {
            if (IsClosed)
            {
                return;
            }

            int queueSize;

            if (checkQueueSize && (queueSize = _connection.SendQueueSize) > ConnectionQueueSizeThreshold)
            {
                SendBadRequestAndClose(Guid.Empty, string.Format("Connection queue size is too large: {0}.", queueSize));
                return;
            }

            var data   = package.AsArraySegment();
            var framed = _framer.FrameData(data);

            _connection.EnqueueSend(framed);
        }