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


C# ByteBuffer.Reset方法代码示例

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


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

示例1: Encode

        public static ByteBuffer Encode(FrameType type, ushort channel, Transfer transfer,
            ByteBuffer payload, int maxFrameSize, out int payloadSize)
        {
            int bufferSize = cmdBufferSize + payload.Length;
            if (bufferSize > maxFrameSize)
            {
                bufferSize = maxFrameSize;
            }

            bool more = false;   // estimate it first
            if (payload.Length > bufferSize - 32)
            {
                transfer.More = more = true;
            }

            ByteBuffer buffer = new ByteBuffer(bufferSize, false);
            EncodeFrame(buffer, type, channel, transfer);

            if (more && payload.Length <= buffer.Size)
            {
                // guessed it wrong. correct it
                transfer.More = false;
                buffer.Reset();
                EncodeFrame(buffer, type, channel, transfer);
            }

            payloadSize = Math.Min(payload.Length, buffer.Size);
            AmqpBitConverter.WriteBytes(buffer, payload.Buffer, payload.Offset, payloadSize);
            payload.Complete(payloadSize);
            AmqpBitConverter.WriteInt(buffer.Buffer, 0, buffer.Length);
            return buffer;
        }
开发者ID:rajeshganesh,项目名称:amqpnetlite,代码行数:32,代码来源:Frame.cs

示例2: test

        public static void test(int level, ByteBuffer b, bool direct)
        {
            Show(level, b);

            if (direct != b.IsDirect)
                fail("Wrong direction", b);

            // Gets and puts

            relPut(b);
            relGet(b);
            absGet(b);
            bulkGet(b);

            absPut(b);
            relGet(b);
            absGet(b);
            bulkGet(b);

            bulkPutArray(b);
            relGet(b);

            bulkPutBuffer(b);
            relGet(b);


            // Compact

            relPut(b);
            b.Position = (13);
            b.Compact();
            b.Flip();
            relGet(b, 13);

            // Exceptions

            relPut(b);
            b.Limit = (b.Capacity / 2);
            b.Position = (b.Limit);

            tryCatch(b, typeof(BufferUnderflowException), () =>
            {
                b.Get();
            });

            tryCatch(b, typeof(BufferOverflowException), () =>
            {
                b.Put((byte)42);
            });

            // The index must be non-negative and lesss than the buffer's limit.
            tryCatch(b, typeof(IndexOutOfRangeException), () =>
            {
                b.Get(b.Limit);
            });
            tryCatch(b, typeof(IndexOutOfRangeException), () =>
            {
                b.Get(-1);
            });

            tryCatch(b, typeof(IndexOutOfRangeException), () =>
            {
                b.Put(b.Limit, (byte)42);
            });

            tryCatch(b, typeof(InvalidMarkException), () =>
            {
                b.Position = (0);
                b.Mark();
                b.Compact();
                b.Reset();
            });

            // Values

            b.Clear();
            b.Put((byte)0);
            b.Put(unchecked((byte)-1));
            b.Put((byte)1);
            b.Put(unchecked((byte)sbyte.MaxValue));
            b.Put(unchecked((byte)sbyte.MinValue));

            byte v;
            b.Flip();
            ck(b, b.Get(), 0);
            ck(b, b.Get(), unchecked((byte)-1));
            ck(b, b.Get(), 1);
            ck(b, b.Get(), unchecked((byte)sbyte.MaxValue));
            ck(b, b.Get(), unchecked((byte)sbyte.MinValue));


            // Comparison
            b.Rewind();
            ByteBuffer b2 = Lucene.Net.Support.ByteBuffer.Allocate(b.Capacity);
            b2.Put(b);
            b2.Flip();
            b.Position = (2);
            b2.Position = (2);
            if (!b.Equals(b2))
            {
//.........这里部分代码省略.........
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:101,代码来源:TestByteBuffer.cs


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