当前位置: 首页>>代码示例>>C#>>正文


C# IByteBuffer.GetByte方法代码示例

本文整理汇总了C#中IByteBuffer.GetByte方法的典型用法代码示例。如果您正苦于以下问题:C# IByteBuffer.GetByte方法的具体用法?C# IByteBuffer.GetByte怎么用?C# IByteBuffer.GetByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IByteBuffer的用法示例。


在下文中一共展示了IByteBuffer.GetByte方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Equals

        /// <summary>
        ///  Returns {@code true} if and only if the two specified buffers are
        ///  identical to each other for {@code length} bytes starting at {@code aStartIndex}
        ///  index for the {@code a} buffer and {@code bStartIndex} index for the {@code b} buffer.
        ///  A more compact way to express this is:
        ///  <p>
        ///  {@code a[aStartIndex : aStartIndex + length] == b[bStartIndex : bStartIndex + length]}
        /// </summary>
        public static bool Equals(IByteBuffer a, int aStartIndex, IByteBuffer b, int bStartIndex, int length)
        {
            if (aStartIndex < 0 || bStartIndex < 0 || length < 0)
            {
                throw new ArgumentException("All indexes and lengths must be non-negative");
            }
            if (a.WriterIndex - length < aStartIndex || b.WriterIndex - length < bStartIndex)
            {
                return false;
            }

            int longCount = unchecked((int)((uint)length >> 3));
            int byteCount = length & 7;

            if (a.Order == b.Order)
            {
                for (int i = longCount; i > 0; i --)
                {
                    if (a.GetLong(aStartIndex) != b.GetLong(bStartIndex))
                    {
                        return false;
                    }
                    aStartIndex += 8;
                    bStartIndex += 8;
                }
            }
            else
            {
                for (int i = longCount; i > 0; i --)
                {
                    if (a.GetLong(aStartIndex) != SwapLong(b.GetLong(bStartIndex)))
                    {
                        return false;
                    }
                    aStartIndex += 8;
                    bStartIndex += 8;
                }
            }

            for (int i = byteCount; i > 0; i --)
            {
                if (a.GetByte(aStartIndex) != b.GetByte(bStartIndex))
                {
                    return false;
                }
                aStartIndex ++;
                bStartIndex ++;
            }

            return true;
        }
开发者ID:dalong123,项目名称:DotNetty,代码行数:59,代码来源:ByteBufferUtil.cs

示例2: GetEncryptedPacketLength

        const int MAX_PLAINTEXT_LENGTH = 16 * 1024; // 2^14

        #endregion Fields

        #region Methods

        /// <summary>
        ///     Return how much bytes can be read out of the encrypted data. Be aware that this method will not increase
        ///     the readerIndex of the given <see cref="IByteBuffer"/>.
        /// </summary>
        /// <param name="buffer">
        ///     The <see cref="IByteBuffer"/> to read from. Be aware that it must have at least
        ///     <see cref="SSL_RECORD_HEADER_LENGTH"/> bytes to read,
        ///     otherwise it will throw an <see cref="ArgumentException"/>.
        /// </param>
        /// <param name="offset">Offset to record start.</param>
        /// <returns>
        ///     The length of the encrypted packet that is included in the buffer. This will
        ///     return <c>-1</c> if the given <see cref="IByteBuffer"/> is not encrypted at all.
        /// </returns>
        public static int GetEncryptedPacketLength(IByteBuffer buffer, int offset)
        {
            int packetLength = 0;

            // SSLv3 or TLS - Check ContentType
            switch (buffer.GetByte(offset))
            {
                case SSL_CONTENT_TYPE_CHANGE_CIPHER_SPEC:
                case SSL_CONTENT_TYPE_ALERT:
                case SSL_CONTENT_TYPE_HANDSHAKE:
                case SSL_CONTENT_TYPE_APPLICATION_DATA:
                    break;
                default:
                    // SSLv2 or bad data
                    return -1;
            }
            // SSLv3 or TLS - Check ProtocolVersion
            int majorVersion = buffer.GetByte(offset + 1);
            if (majorVersion == 3)
            {
                // SSLv3 or TLS
                packetLength = buffer.GetUnsignedShort(offset + 3) + SSL_RECORD_HEADER_LENGTH;
                if (packetLength <= SSL_RECORD_HEADER_LENGTH)
                {
                    // Neither SSLv3 or TLSv1 (i.e. SSLv2 or bad data)
                    return -1;
                }
            }
            else
            {
                // Neither SSLv3 or TLSv1 (i.e. SSLv2 or bad data)
                return -1;
            }

            return packetLength;
        }
开发者ID:RabbitTeam,项目名称:DotNetty,代码行数:56,代码来源:TlsUtils.cs

示例3: GetUnadjustedFrameLength

 /// <summary>
 ///     Decodes the specified region of the buffer into an unadjusted frame length.  The default implementation is
 ///     capable of decoding the specified region into an unsigned 8/16/24/32/64 bit integer.  Override this method to
 ///     decode the length field encoded differently.
 ///     Note that this method must not modify the state of the specified buffer (e.g.
 ///     <see cref="IByteBuffer.ReaderIndex" />,
 ///     <see cref="IByteBuffer.WriterIndex" />, and the content of the buffer.)
 /// </summary>
 /// <param name="buffer">The buffer we'll be extracting the frame length from.</param>
 /// <param name="offset">The offset from the absolute <see cref="IByteBuffer.ReaderIndex" />.</param>
 /// <param name="length">The length of the framelenght field. Expected: 1, 2, 3, 4, or 8.</param>
 /// <param name="order">The preferred <see cref="ByteOrder" /> of <see cref="buffer" />.</param>
 /// <returns>A long integer that represents the unadjusted length of the next frame.</returns>
 protected long GetUnadjustedFrameLength(IByteBuffer buffer, int offset, int length, ByteOrder order)
 {
     buffer = buffer.WithOrder(order);
     long frameLength;
     switch (length)
     {
         case 1:
             frameLength = buffer.GetByte(offset);
             break;
         case 2:
             frameLength = buffer.GetShort(offset);
             break;
         case 4:
             frameLength = buffer.GetInt(offset);
             break;
         case 8:
             frameLength = buffer.GetLong(offset);
             break;
         default:
             throw new DecoderException("unsupported lengthFieldLength: " + this.lengthFieldLength + " (expected: 1, 2, 3, 4, or 8)");
     }
     return frameLength;
 }
开发者ID:RabbitTeam,项目名称:DotNetty,代码行数:36,代码来源:LengthFieldBasedFrameDecoder.cs

示例4: AppendPrettyHexDump

        /// <summary>
        /// Appends the prettified multi-line hexadecimal dump of the specified {@link ByteBuf} to the specified
        /// {@link StringBuilder} that is easy to read by humans, starting at the given {@code offset} using
        /// the given {@code length}.
        /// </summary>
        public static void AppendPrettyHexDump(StringBuilder dump, IByteBuffer buf, int offset, int length)
        {
            if (offset < 0 || length > buf.Capacity - offset)
            {
                throw new IndexOutOfRangeException(
                    "expected: " + "0 <= offset(" + offset + ") <= offset + length(" + length
                        + ") <= " + "buf.capacity(" + buf.Capacity + ')');
            }
            if (length == 0)
            {
                return;
            }
            dump.Append(
                "         +-------------------------------------------------+" +
                    Newline + "         |  0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f |" +
                    Newline + "+--------+-------------------------------------------------+----------------+");

            int startIndex = offset;
            int fullRows = (int)((uint)length >> 4);
            int remainder = length & 0xF;

            // Dump the rows which have 16 bytes.
            for (int row = 0; row < fullRows; row++)
            {
                int rowStartIndex = (row << 4) + startIndex;

                // Per-row prefix.
                AppendHexDumpRowPrefix(dump, row, rowStartIndex);

                // Hex dump
                int rowEndIndex = rowStartIndex + 16;
                for (int j = rowStartIndex; j < rowEndIndex; j++)
                {
                    dump.Append(Byte2Hex[buf.GetByte(j)]);
                }
                dump.Append(" |");

                // ASCII dump
                for (int j = rowStartIndex; j < rowEndIndex; j++)
                {
                    dump.Append(Byte2Char[buf.GetByte(j)]);
                }
                dump.Append('|');
            }

            // Dump the last row which has less than 16 bytes.
            if (remainder != 0)
            {
                int rowStartIndex = (fullRows << 4) + startIndex;
                AppendHexDumpRowPrefix(dump, fullRows, rowStartIndex);

                // Hex dump
                int rowEndIndex = rowStartIndex + remainder;
                for (int j = rowStartIndex; j < rowEndIndex; j++)
                {
                    dump.Append(Byte2Hex[buf.GetByte(j)]);
                }
                dump.Append(HexPadding[remainder]);
                dump.Append(" |");

                // Ascii dump
                for (int j = rowStartIndex; j < rowEndIndex; j++)
                {
                    dump.Append(Byte2Char[buf.GetByte(j)]);
                }
                dump.Append(BytePadding[remainder]);
                dump.Append('|');
            }

            dump.Append(Newline + "+--------+-------------------------------------------------+----------------+");
        }
开发者ID:donmikel,项目名称:DotNetty,代码行数:76,代码来源:ByteBufferUtil.cs

示例5: Compare

        /// <summary>
        /// Compares the two specified buffers as described in {@link ByteBuf#compareTo(ByteBuf)}.
        /// This method is useful when implementing a new buffer type.
        /// </summary>
        public static int Compare(IByteBuffer bufferA, IByteBuffer bufferB)
        {
            int aLen = bufferA.ReadableBytes;
            int bLen = bufferB.ReadableBytes;
            int minLength = Math.Min(aLen, bLen);
            int uintCount = (int)((uint)minLength >> 2);
            int byteCount = minLength & 3;

            int aIndex = bufferA.ReaderIndex;
            int bIndex = bufferB.ReaderIndex;

            if (bufferA.Order == bufferB.Order)
            {
                for (int i = uintCount; i > 0; i--)
                {
                    long va = bufferA.GetUnsignedInt(aIndex);
                    long vb = bufferB.GetUnsignedInt(bIndex);
                    if (va > vb)
                    {
                        return 1;
                    }
                    if (va < vb)
                    {
                        return -1;
                    }
                    aIndex += 4;
                    bIndex += 4;
                }
            }
            else
            {
                for (int i = uintCount; i > 0; i--)
                {
                    long va = bufferA.GetUnsignedInt(aIndex);
                    long vb = SwapInt(bufferB.GetInt(bIndex)) & 0xFFFFFFFFL;
                    if (va > vb)
                    {
                        return 1;
                    }
                    if (va < vb)
                    {
                        return -1;
                    }
                    aIndex += 4;
                    bIndex += 4;
                }
            }

            for (int i = byteCount; i > 0; i--)
            {
                short va = bufferA.GetByte(aIndex);
                short vb = bufferB.GetByte(bIndex);
                if (va > vb)
                {
                    return 1;
                }
                if (va < vb)
                {
                    return -1;
                }
                aIndex++;
                bIndex++;
            }

            return aLen - bLen;
        }
开发者ID:donmikel,项目名称:DotNetty,代码行数:70,代码来源:ByteBufferUtil.cs

示例6: HashCode

        /// <summary>
        /// Calculates the hash code of the specified buffer.  This method is
        /// useful when implementing a new buffer type.
        /// </summary>
        public static int HashCode(IByteBuffer buffer)
        {
            int aLen = buffer.ReadableBytes;
            int intCount = (int)((uint)aLen >> 2);
            int byteCount = aLen & 3;

            int hashCode = 1;
            int arrayIndex = buffer.ReaderIndex;
            if (buffer.Order == ByteOrder.BigEndian)
            {
                for (int i = intCount; i > 0; i--)
                {
                    hashCode = 31 * hashCode + buffer.GetInt(arrayIndex);
                    arrayIndex += 4;
                }
            }
            else
            {
                for (int i = intCount; i > 0; i--)
                {
                    hashCode = 31 * hashCode + SwapInt(buffer.GetInt(arrayIndex));
                    arrayIndex += 4;
                }
            }

            for (int i = byteCount; i > 0; i--)
            {
                hashCode = 31 * hashCode + buffer.GetByte(arrayIndex++);
            }

            if (hashCode == 0)
            {
                hashCode = 1;
            }

            return hashCode;
        }
开发者ID:donmikel,项目名称:DotNetty,代码行数:41,代码来源:ByteBufferUtil.cs

示例7: HexDump

        /// <summary>
        /// Returns a <a href="http://en.wikipedia.org/wiki/Hex_dump">hex dump</a>
        /// of the specified buffer's sub-region.
        /// </summary>
        public static string HexDump(IByteBuffer buffer, int fromIndex, int length)
        {
            Contract.Requires(length >= 0);
            if (length == 0)
            {
                return "";
            }
            int endIndex = fromIndex + length;
            char[] buf = new char[length << 1];

            int srcIdx = fromIndex;
            int dstIdx = 0;
            for (; srcIdx < endIndex; srcIdx++, dstIdx += 2)
            {
                Array.Copy(
                    HexdumpTable, buffer.GetByte(srcIdx) << 1,
                    buf, dstIdx, 2);
            }

            return new string(buf);
        }
开发者ID:donmikel,项目名称:DotNetty,代码行数:25,代码来源:ByteBufferUtil.cs

示例8: IndexOf

        /**
         * Returns the number of bytes between the readerIndex of the haystack and
         * the first needle found in the haystack.  -1 is returned if no needle is
         * found in the haystack.
         */

        static int IndexOf(IByteBuffer haystack, IByteBuffer needle)
        {
            for (int i = haystack.ReaderIndex; i < haystack.WriterIndex; i++)
            {
                int haystackIndex = i;
                int needleIndex;
                for (needleIndex = 0; needleIndex < needle.Capacity; needleIndex++)
                {
                    if (haystack.GetByte(haystackIndex) != needle.GetByte(needleIndex))
                    {
                        break;
                    }
                    else
                    {
                        haystackIndex++;
                        if (haystackIndex == haystack.WriterIndex && needleIndex != needle.Capacity - 1)
                        {
                            return -1;
                        }
                    }
                }

                if (needleIndex == needle.Capacity)
                {
                    // Found the needle from the haystack!
                    return i - haystack.ReaderIndex;
                }
            }
            return -1;
        }
开发者ID:RabbitTeam,项目名称:DotNetty,代码行数:36,代码来源:DelimiterBasedFrameDecoder.cs

示例9: SkipNullBytes

        /// <summary>
        /// Skips the null bytes.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns><c>true</c> if successful, <c>false</c> otherwise.</returns>
        private static bool SkipNullBytes(IByteBuffer input)
        {
            while (input.IsReadable())
            {
                if (input.GetByte(input.ReaderIndex) != 0xFF) return true;
                input.SkipBytes(1);
            }

            return false;
        }
开发者ID:bradsjm,项目名称:DotEmwin,代码行数:15,代码来源:ByteBlasterProtocolDecoder.cs

示例10: IsServerList

 /// <summary>
 /// Determines whether the buffer contains a server list.
 /// </summary>
 /// <param name="input">The input.</param>
 /// <returns><c>true</c> if the buffer contains a server list header; otherwise, <c>false</c>.</returns>
 private static bool IsServerList(IByteBuffer input) =>
             ((input.GetByte(input.ReaderIndex) ^ 0xFF) == '/' &&
              (input.GetByte(input.ReaderIndex + 1) ^ 0xFF) == 'S' &&
              (input.GetByte(input.ReaderIndex + 2) ^ 0xFF) == 'e');
开发者ID:bradsjm,项目名称:DotEmwin,代码行数:9,代码来源:ByteBlasterProtocolDecoder.cs

示例11: ReadString

        /// <summary>
        /// Reads the string from the byte buffer until null terminator.
        /// </summary>
        /// <param name="input">The input.</param>
        /// <returns>System.String.</returns>
        private static string ReadString(IByteBuffer input)
        {
            // Scan buffer for end of string null terminator
            for (var index = input.ReaderIndex; index < input.WriterIndex; index++)
            {
                if (input.GetByte(index) != 0xFF) continue;

                var bytes = XorArray(input.ReadBytes(index - input.ReaderIndex).ToArray());
                return Encoding.ASCII.GetString(bytes);
            }

            return string.Empty;
        }
开发者ID:bradsjm,项目名称:DotEmwin,代码行数:18,代码来源:ByteBlasterProtocolDecoder.cs

示例12: IsDataBlockHeader

 /// <summary>
 /// Determines whether the buffer contains a data block header.
 /// </summary>
 /// <param name="input">The input.</param>
 /// <returns><c>true</c> if the buffer contains a data block header; otherwise, <c>false</c>.</returns>
 private static bool IsDataBlockHeader(IByteBuffer input) =>
     ((input.GetByte(input.ReaderIndex) ^ 0xFF) == '/' &&
      (input.GetByte(input.ReaderIndex + 1) ^ 0xFF) == 'P' &&
      (input.GetByte(input.ReaderIndex + 2) ^ 0xFF) == 'F');
开发者ID:bradsjm,项目名称:DotEmwin,代码行数:9,代码来源:ByteBlasterProtocolDecoder.cs

示例13: Decode

        protected internal override void Decode(IChannelHandlerContext context, IByteBuffer input, List<object> output)
        {
            if (this.state == StCorrupted)
            {
                input.SkipBytes(input.ReadableBytes);
                return;
            }

            // index of next byte to process.
            int idx = this.idx;
            int wrtIdx = input.WriterIndex;

            if (wrtIdx > this.maxObjectLength)
            {
                // buffer size exceeded maxObjectLength; discarding the complete buffer.
                input.SkipBytes(input.ReadableBytes);
                this.Reset();
                throw new TooLongFrameException($"Object length exceeds {this.maxObjectLength}: {wrtIdx} bytes discarded");
            }

            for ( /* use current idx */; idx < wrtIdx; idx++)
            {
                byte c = input.GetByte(idx);

                if (this.state == StDecodingNormal)
                {
                    this.DecodeByte(c, input, idx);

                    // All opening braces/brackets have been closed. That's enough to conclude
                    // that the JSON object/array is complete.
                    if (this.openBraces == 0)
                    {
                        IByteBuffer json = this.ExtractObject(context, input, input.ReaderIndex, idx + 1 - input.ReaderIndex);
                        if (json != null)
                        {
                            output.Add(json);
                        }

                        // The JSON object/array was extracted => discard the bytes from
                        // the input buffer.
                        input.SetReaderIndex(idx + 1);

                        // Reset the object state to get ready for the next JSON object/text
                        // coming along the byte stream.
                        this.Reset();
                    }
                }
                else if (this.state == StDecodingArrayStream)
                {
                    this.DecodeByte(c, input, idx);

                    if (!this.insideString && (this.openBraces == 1 && c == ',' || this.openBraces == 0 && c == ']'))
                    {
                        // skip leading spaces. No range check is needed and the loop will terminate
                        // because the byte at position idx is not a whitespace.
                        for (int i = input.ReaderIndex; char.IsWhiteSpace(Convert.ToChar(input.GetByte(i))); i++)
                        {
                            input.SkipBytes(1);
                        }

                        // skip trailing spaces.
                        int idxNoSpaces = idx - 1;
                        while (idxNoSpaces >= input.ReaderIndex && char.IsWhiteSpace(Convert.ToChar(input.GetByte(idxNoSpaces))))
                        {
                            idxNoSpaces--;
                        }

                        IByteBuffer json = this.ExtractObject(context, input, input.ReaderIndex, idxNoSpaces + 1 - input.ReaderIndex);
                        if (json != null)
                        {
                            output.Add(json);
                        }

                        input.SetReaderIndex(idx + 1);

                        if (c == ']')
                        {
                            this.Reset();
                        }
                    }
                }
                else if (c == '{' || c == '[') // JSON object/array detected. Accumulate bytes until all braces/brackets are closed
                {
                    this.InitDecoding(c);

                    if (this.state == StDecodingArrayStream)
                    {
                        //Discard the array bracket
                        input.SkipBytes(1);
                    }
                }
                else if (char.IsWhiteSpace(Convert.ToChar(c))) //Discard leading spaces in from of a JSON object/array
                {
                    input.SkipBytes(1);
                }
                else
                {
                    this.state = StCorrupted;
                    throw new CorruptedFrameException($"Invalid JSON received at byte position {idx}");
                }
//.........这里部分代码省略.........
开发者ID:RabbitTeam,项目名称:DotNetty,代码行数:101,代码来源:JsonObjectDecoder.cs

示例14: DecodeByte

 void DecodeByte(byte c, IByteBuffer input, int idx)
 {
     if ((c == '{' || c == '[') && !this.insideString)
     {
         this.openBraces++;
     }
     else if ((c == '}' || c == ']') && !this.insideString)
     {
         this.openBraces--;
     }
     else if (c == '"')
     {
         // start of a new JSON string. It's necessary to detect strings as they may
         // also contain braces/brackets and that could lead to incorrect results.
         if (!this.insideString)
         {
             this.insideString = true;
             // If the double quote wasn't escaped then this is the end of a string.
         }
         else if (input.GetByte(idx - 1) != '\\')
         {
             this.insideString = false;
         }
     }
 }
开发者ID:RabbitTeam,项目名称:DotNetty,代码行数:25,代码来源:JsonObjectDecoder.cs

示例15: Decode

        /// <summary>
        ///     Create a frame out of the {@link ByteBuf} and return it.
        /// </summary>
        /// <param name="ctx">the {@link ChannelHandlerContext} which this {@link ByteToMessageDecoder} belongs to</param>
        /// <param name="buffer">the {@link ByteBuf} from which to read data</param>
        protected internal object Decode(IChannelHandlerContext ctx, IByteBuffer buffer)
        {
            int eol = this.FindEndOfLine(buffer);
            if (!this.discarding)
            {
                if (eol >= 0)
                {
                    IByteBuffer frame;
                    int length = eol - buffer.ReaderIndex;
                    int delimLength = buffer.GetByte(eol) == '\r' ? 2 : 1;

                    if (length > this.maxLength)
                    {
                        buffer.SetReaderIndex(eol + delimLength);
                        this.Fail(ctx, length);
                        return null;
                    }

                    if (this.stripDelimiter)
                    {
                        frame = buffer.ReadSlice(length);
                        buffer.SkipBytes(delimLength);
                    }
                    else
                    {
                        frame = buffer.ReadSlice(length + delimLength);
                    }

                    return frame.Retain();
                }
                else
                {
                    int length = buffer.ReadableBytes;
                    if (length > this.maxLength)
                    {
                        this.discardedBytes = length;
                        buffer.SetReaderIndex(buffer.WriterIndex);
                        this.discarding = true;
                        if (this.failFast)
                        {
                            this.Fail(ctx, "over " + this.discardedBytes);
                        }
                    }
                    return null;
                }
            }
            else
            {
                if (eol >= 0)
                {
                    int length = this.discardedBytes + eol - buffer.ReaderIndex;
                    int delimLength = buffer.GetByte(eol) == '\r' ? 2 : 1;
                    buffer.SetReaderIndex(eol + delimLength);
                    this.discardedBytes = 0;
                    this.discarding = false;
                    if (!this.failFast)
                    {
                        this.Fail(ctx, length);
                    }
                }
                else
                {
                    this.discardedBytes += buffer.ReadableBytes;
                    buffer.SetReaderIndex(buffer.WriterIndex);
                }
                return null;
            }
        }
开发者ID:RabbitTeam,项目名称:DotNetty,代码行数:73,代码来源:LineBasedFrameDecoder.cs


注:本文中的IByteBuffer.GetByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。