Exemple #1
0
        public void AddValue(string stringValue, int rank)
        {
            if (stringValue is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.stringValue); }

            IByteBuffer buf = ArrayPooled.CopiedBuffer(stringValue, this.charset);
            this.value[rank] = buf;
            this.size += buf.ReadableBytes;
        }
Exemple #2
0
        public IByteBuffer ToByteBuffer()
        {
            CompositeByteBuffer compositeBuffer = ArrayPooled.CompositeBuffer();
            _ = compositeBuffer.AddComponents(this.value);
            _ = compositeBuffer.SetWriterIndex(this.size);
            _ = compositeBuffer.SetReaderIndex(0);

            return compositeBuffer;
        }
Exemple #3
0
        public override void SetContent(Stream inputStream)
        {
            if (inputStream is null)
            {
                ThrowHelper.ThrowArgumentNullException(ExceptionArgument.inputStream);
            }

            if (!inputStream.CanRead)
            {
                ThrowHelper.ThrowArgumentException_Stream_NotReadable();
            }

            var bytes = ArrayPool <byte> .Shared.Rent(c_defaultCopyBufferSize);

            IByteBuffer buffer  = ArrayPooled.Buffer();
            int         written = 0;

            try
            {
                while (true)
                {
                    int read = inputStream.Read(bytes, 0, bytes.Length);
                    if (read <= 0)
                    {
                        break;
                    }

                    _        = buffer.WriteBytes(bytes, 0, read);
                    written += read;
                    CheckSize(written, MaxSize);
                }
            }
            catch (IOException)
            {
                buffer.Release();
                throw;
            }
            finally
            {
                ArrayPool <byte> .Shared.Return(bytes);
            }
            Size = written;
            if (DefinedSize > 0 && DefinedSize < Size)
            {
                buffer.Release();
                ThrowHelper.ThrowIOException_OutOfSize(Size, DefinedSize);
            }

            _        = (_byteBuf?.Release());
            _byteBuf = buffer;
            SetCompleted();
        }
Exemple #4
0
        public void SetValue(string stringValue, int rank)
        {
            if (stringValue is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.stringValue); }

            IByteBuffer buf = ArrayPooled.CopiedBuffer(stringValue, this.charset);
            IByteBuffer old = this.value[rank];
            this.value[rank] = buf;
            if (old is object)
            {
                this.size -= old.ReadableBytes;
                _ = old.Release();
            }
            this.size += buf.ReadableBytes;
        }
        static IByteBuffer NewBinaryData(int statusCode, ICharSequence reasonText)
        {
            if (reasonText is null)
            {
                reasonText = StringCharSequence.Empty;
            }

            IByteBuffer binaryData = ArrayPooled.Buffer(2 + reasonText.Count);

            _ = binaryData.WriteShort(statusCode);
            if ((uint)reasonText.Count > 0u)
            {
                _ = binaryData.WriteCharSequence(reasonText, Encoding.UTF8);
            }

            _ = binaryData.SetReaderIndex(0);
            return(binaryData);
        }
Exemple #6
0
        public override void AddContent(IByteBuffer buffer, bool last)
        {
            if (buffer is object)
            {
                long localsize = buffer.ReadableBytes;
                CheckSize(Size + localsize, MaxSize);
                if (DefinedSize > 0 && DefinedSize < Size + localsize)
                {
                    ThrowHelper.ThrowIOException_OutOfSize(Size + localsize, DefinedSize);
                }

                Size += localsize;
                if (_byteBuf is null)
                {
                    _byteBuf = buffer;
                }
                else if (_byteBuf is CompositeByteBuffer buf)
                {
                    _ = buf.AddComponent(true, buffer);
                    _ = buf.SetWriterIndex((int)Size);
                }
                else
                {
                    CompositeByteBuffer compositeBuffer = ArrayPooled.CompositeBuffer(int.MaxValue);
                    _        = compositeBuffer.AddComponents(true, _byteBuf, buffer);
                    _        = compositeBuffer.SetWriterIndex((int)Size);
                    _byteBuf = compositeBuffer;
                }
            }
            if (last)
            {
                SetCompleted();
            }
            else
            {
                if (buffer is null)
                {
                    ThrowHelper.ThrowArgumentNullException(ExceptionArgument.buffer);
                }
            }
        }
 /// <summary>
 /// Creates a new empty binary frame.
 /// </summary>
 public BinaryWebSocketFrame()
     : base(true, 0, Opcode.Binary, ArrayPooled.Buffer(0))
 {
 }
 /// <summary>
 /// Creates a new close frame with no losing status code and no reason text
 /// </summary>
 /// <param name="finalFragment">flag indicating if this frame is the final fragment</param>
 /// <param name="rsv">reserved bits used for protocol extensions.</param>
 public CloseWebSocketFrame(bool finalFragment, int rsv)
     : base(finalFragment, rsv, Opcode.Close, ArrayPooled.Buffer(0))
 {
 }
 /// <summary>
 /// Creates a new empty close frame.
 /// </summary>
 public CloseWebSocketFrame()
     : base(true, 0, Opcode.Close, ArrayPooled.Buffer(0))
 {
 }
Exemple #10
0
 /// <summary>
 /// Sets the string for this frame.
 /// </summary>
 /// <param name="text">text to store.</param>
 /// <returns></returns>
 static IByteBuffer FromText(string text) => string.IsNullOrEmpty(text)
     ? Unpooled.Empty : ArrayPooled.EncodeString(text, Encoding.UTF8);
Exemple #11
0
 /// <summary>
 /// Creates a new empty continuation frame.
 /// </summary>
 public ContinuationWebSocketFrame()
     : base(true, 0, Opcode.Cont, ArrayPooled.Buffer(0))
 {
 }
Exemple #12
0
 /// <summary>
 /// Creates a new empty text frame.
 /// </summary>
 public TextWebSocketFrame()
     : base(true, 0, Opcode.Text, ArrayPooled.Buffer(0))
 {
 }
Exemple #13
0
 public DefaultFullHttpRequest(HttpVersion httpVersion, HttpMethod method, string uri, bool validateHeaders)
     : this(httpVersion, method, uri, ArrayPooled.Buffer(0), validateHeaders)
 {
 }
Exemple #14
0
 public DefaultFullHttpRequest(HttpVersion httpVersion, HttpMethod method, string uri)
     : this(httpVersion, method, uri, ArrayPooled.Buffer(0), true)
 {
 }
 public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status)
     : this(version, status, ArrayPooled.Buffer(0), true, false)
 {
 }
Exemple #16
0
 public PingWebSocketFrame()
     : base(true, 0, Opcode.Ping, ArrayPooled.Buffer(0))
 {
 }
 public DefaultFullHttpResponse(HttpVersion version, HttpResponseStatus status, bool validateHeaders,
                                bool singleFieldHeaders)
     : this(version, status, ArrayPooled.Buffer(0), validateHeaders, singleFieldHeaders)
 {
 }
Exemple #18
0
 public DefaultLastHttpContent() : this(ArrayPooled.Buffer(0), true)
 {
 }