Esempio n. 1
0
        /// <inheritdoc />
        protected internal override void EncodeInitialLine(IByteBuffer buf, IHttpRequest request)
        {
            ByteBufferUtil.Copy(request.Method.AsciiName, buf);

            string uri = request.Uri;

            if (string.IsNullOrEmpty(uri))
            {
                // Add / as absolute path if no is present.
                // See http://tools.ietf.org/html/rfc2616#section-5.1.2
                _ = buf.WriteMedium(SpaceSlashAndSpaceMedium);
            }
            else
            {
                var uriCharSequence = new StringBuilderCharSequence();
                uriCharSequence.Append(uri);

                bool needSlash = false;
                int  start     = uri.IndexOf("://", StringComparison.Ordinal);
                if (start != -1 && uri[0] != Slash)
                {
                    start += 3;
                    // Correctly handle query params.
                    // See https://github.com/netty/netty/issues/2732
                    int index = uri.IndexOf(QuestionMark, start);
                    if (index == -1)
                    {
                        if (uri.LastIndexOf(Slash) < start)
                        {
                            needSlash = true;
                        }
                    }
                    else
                    {
                        if (uri.LastIndexOf(Slash, index) < start)
                        {
                            uriCharSequence.Insert(index, Slash);
                        }
                    }
                }

                _ = buf.WriteByte(HorizontalSpace).WriteCharSequence(uriCharSequence, Encoding.UTF8);
                if (needSlash)
                {
                    // write "/ " after uri
                    _ = buf.WriteShort(SlashAndSpaceShort);
                }
                else
                {
                    _ = buf.WriteByte(HorizontalSpace);
                }
            }

            request.ProtocolVersion.Encode(buf);
            _ = buf.WriteShort(CrlfShort);
        }
Esempio n. 2
0
 static void WriteAscii(IByteBuffer buf, int offset, ICharSequence value)
 {
     if (value is AsciiString asciiString)
     {
         ByteBufferUtil.Copy(asciiString, 0, buf, offset, value.Count);
     }
     else
     {
         buf.SetCharSequence(offset, value, Encoding.ASCII);
     }
 }
        public static void SetFloat(byte[] dst, ref int startIndex, float value)
        {
            byte[] src = BitConverter.GetBytes(value);

            if (ByteBufferUtil.IsReveresed(_endian))
            {
                Array.Reverse(src);
            }
            ByteBufferUtil.Copy(src, 0, dst, startIndex, src.Length);

            startIndex += sizeof(float);
        }
Esempio n. 4
0
 protected override void SetShort(short data)
 {
     ByteBufferUtil.Copy(BitConverter.GetBytes(data), 0, _data, _writeIndex, sizeof(short));
 }
Esempio n. 5
0
 protected override void SetLong(long data)
 {
     ByteBufferUtil.Copy(BitConverter.GetBytes(data), 0, _data, _writeIndex, sizeof(long));
 }
        protected override void SetShort(short data)
        {
            var bytes = BitConverter.GetBytes(data.Reverse());

            ByteBufferUtil.Copy(bytes, 0, _data, _writeIndex, sizeof(short));
        }