Exemplo n.º 1
0
        public int ForEachByte(IByteProcessor processor)
        {
            int ret = _buffer.ForEachByte(processor);

            if ((uint)ret > SharedConstants.TooBigOrNegative)
            {
                ThrowReplay();
            }
            return(ret);
        }
Exemplo n.º 2
0
        long ParsePositiveNumber(IByteBuffer byteBuffer)
        {
            this.toPositiveLongProcessor.Reset();
            byteBuffer.ForEachByte(this.toPositiveLongProcessor);

            return(this.toPositiveLongProcessor.Content);
        }
Exemplo n.º 3
0
        private int FindEndOfLine(IByteBuffer byteBuffer)
        {
            var chars    = terminator.ToCharArray();
            var byteChar = (byte)chars[0];

            var index = byteBuffer.ForEachByte(new ByteProcessor(b => b != byteChar));

            if (index != -1)
            {
                for (int i = 1; i < chars.Length; i++)
                {
                    var chatByte = (byte)chars[i];
                    if (index > byteBuffer.ReadableBytes)
                    {
                        index = -1;
                        break;
                    }
                    var byteItem = byteBuffer.GetByte(index + 1);
                    if (chatByte == byteItem)
                    {
                        index += 1;
                    }
                    else
                    {
                        index = -1;
                        break;
                    }
                }
            }
            if (index != -1)
            {
                index -= chars.Length - 1;
            }
            return(index);
        }
Exemplo n.º 4
0
 /// <summary>
 ///     Iterates over the readable bytes of this buffer with the specified <c>processor</c> in ascending order.
 /// </summary>
 /// <returns>
 ///     <c>-1</c> if the processor iterated to or beyond the end of the readable bytes.
 ///     The last-visited index If the <see cref="IByteProcessor.Process" /> returned <c>false</c>.
 /// </returns>
 public static int ForEachByte(this IByteBuffer buf, IByteProcessor processor)
 {
     if (buf is IByteBuffer2 buffer2)
     {
         return(buffer2.ForEachByte(processor));
     }
     return(buf.ForEachByte(buf.ReaderIndex, buf.ReadableBytes, processor));
 }
Exemplo n.º 5
0
        static int FirstIndexOf(IByteBuffer buffer, int fromIndex, int toIndex, byte value)
        {
            fromIndex = Math.Max(fromIndex, 0);
            if (fromIndex >= toIndex || buffer.Capacity == 0)
            {
                return(-1);
            }

            return(buffer.ForEachByte(fromIndex, toIndex - fromIndex, new ByteProcessor.IndexOfProcessor(value)));
        }
        int FindEndOfLine(IByteBuffer buffer)
        {
            int i = buffer.ForEachByte(ByteProcessor.FIND_LF);

            if (i > 0 && buffer.GetByte(i - 1) == '\r')
            {
                i--;
            }

            return(i);
        }
Exemplo n.º 7
0
            public virtual AppendableCharSequence Parse(IByteBuffer buffer)
            {
                int oldSize = _size;

                _seq.Reset();
                int i = buffer.ForEachByte(this);

                if (i == -1)
                {
                    _size = oldSize;
                    return(null);
                }
                _ = buffer.SetReaderIndex(i + 1);
                return(_seq);
            }
        static IByteBuffer ReadLine(IByteBuffer input)
        {
            if (!input.IsReadable(RedisConstants.EndOfLineLength))
            {
                return(null);
            }

            int lfIndex = input.ForEachByte(ByteProcessor.FindLF);

            if (lfIndex < 0)
            {
                return(null);
            }

            IByteBuffer data = input.ReadSlice(lfIndex - input.ReaderIndex - 1); // `-1` is for CR

            ReadEndOfLine(input);                                                // validate CR LF
            return(data);
        }
Exemplo n.º 9
0
        static IByteBuffer ReadLine(IByteBuffer byteBuffer)
        {
            Contract.Requires(byteBuffer != null);

            if (!byteBuffer.IsReadable(RedisConstants.EndOfLineLength))
            {
                return(null);
            }

            int lfIndex = byteBuffer.ForEachByte(ByteProcessor.FIND_LF);

            if (lfIndex < 0)
            {
                return(null);
            }

            IByteBuffer buffer = byteBuffer.ReadSlice(lfIndex - byteBuffer.ReaderIndex - 1);

            ReadEndOfLine(byteBuffer);

            return(buffer);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Decompresses the given Huffman coded string literal.
        /// </summary>
        /// <param name="buf">the string literal to be decoded</param>
        /// <param name="length"></param>
        /// <returns>the output stream for the compressed data</returns>
        /// <exception cref="Http2Exception">EOS Decoded</exception>
        public AsciiString Decode(IByteBuffer buf, int length)
        {
            if (0u >= (uint)length)
            {
                return(AsciiString.Empty);
            }

            _dest = new byte[length * 8 / 5];
            try
            {
                int readerIndex = buf.ReaderIndex;
                // Using ByteProcessor to reduce bounds-checking and reference-count checking during byte-by-byte
                // processing of the ByteBuf.
                int endIndex = buf.ForEachByte(readerIndex, length, this);
                if ((uint)endIndex > SharedConstants.TooBigOrNegative) // == -1
                {
                    // We did consume the requested length
                    _ = buf.SetReaderIndex(readerIndex + length);
                    if ((_state & HUFFMAN_COMPLETE_SHIFT) != HUFFMAN_COMPLETE_SHIFT)
                    {
                        ThrowBadEncoding();
                    }
                    return(new AsciiString(_dest, 0, _k, false));
                }

                // The process(...) method returned before the requested length was requested. This means there
                // was a bad encoding detected.
                _ = buf.SetReaderIndex(endIndex);
                throw s_badEncoding;
            }
            finally
            {
                _dest  = null;
                _k     = 0;
                _state = 0;
            }
        }
Exemplo n.º 11
0
 public virtual int ForEachByte(int index, int length, IByteProcessor processor) => Buf.ForEachByte(index, length, processor);
Exemplo n.º 12
0
 public void Check(IByteBuffer buffer)
 {
     _checking = true;
     _         = buffer.ForEachByte(this);
 }
Exemplo n.º 13
0
 private static int FindStarterIndex(IByteBuffer input)
 {
     //等同于for循环去查找input中starter的下标,没有就返回-1
     return(input.ForEachByte(new IndexOfProcessor(GkDefault.Starter)));
 }
Exemplo n.º 14
0
 static bool IsAscii(IByteBuffer buf, int index, int length) => buf.ForEachByte(index, length, AsciiByteProcessor) == -1;
Exemplo n.º 15
0
        static int FirstIndexOf(IByteBuffer buffer, int fromIndex, int toIndex, byte value)
        {
            fromIndex = Math.Max(fromIndex, 0);
            if (fromIndex >= toIndex || buffer.Capacity == 0)
            {
                return -1;
            }

            return buffer.ForEachByte(fromIndex, toIndex - fromIndex, new ByteProcessor.IndexOfProcessor(value));
        }
Exemplo n.º 16
0
        int FindEndOfLine(IByteBuffer buffer)
        {
            int i = buffer.ForEachByte(ByteProcessor.FIND_LF);
            if (i > 0 && buffer.GetByte(i - 1) == '\r')
            {
                i--;
            }

            return i;
        }