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


C# CircularBuffer.Consume方法代码示例

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


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

示例1: CircularBufferExt_DecoderConvert2_IncompleteBuff

        public void CircularBufferExt_DecoderConvert2_IncompleteBuff()
        {
            Encoding enc = Encoding.GetEncoding("UTF-8");
            Decoder d = enc.GetDecoder();
            byte[] m = new byte[] {
                0xAC, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46,
                0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E,
                0x4F, 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56,
                0x57, 0x58, 0x59, 0x5A, 0xE2, 0x82
            };
            char[] c = new char[30];
            CircularBuffer<byte> cb = new CircularBuffer<byte>(m, 16, 13);
            CircularBuffer<char> cc = new CircularBuffer<char>(c, 5, 0);

            int bu;
            int cu;
            bool complete;

            // Based on the test "Decoder_IncompleteBuff"
            d.Convert(cb, cc, cc.Free, false, out bu, out cu, out complete);
            Assert.IsTrue(complete);
            Assert.AreEqual(13, bu);
            Assert.AreEqual(0, cb.Length);
            Assert.AreEqual(12, cu);
            Assert.AreEqual("OPQRSTUVWXYZ", cc.GetString());
            cc.Consume(cu);

            cb.Produce(17);
            d.Convert(cb, cc, cc.Free, false, out bu, out cu, out complete);
            Assert.IsTrue(complete);
            Assert.AreEqual(17, bu);
            Assert.AreEqual(0, cb.Length);
            Assert.AreEqual(16, cu);
            Assert.AreEqual("€@ABCDEFGHIJKLMN", cc.GetString());
        }
开发者ID:DHMechatronicAG,项目名称:SerialPortStream,代码行数:35,代码来源:CircularBufferTest.cs

示例2: CircularBufferExt_DecoderConvert3_BoundariesWithFlush

        public void CircularBufferExt_DecoderConvert3_BoundariesWithFlush()
        {
            Encoding enc = Encoding.GetEncoding("UTF-8");
            Decoder d = enc.GetDecoder();

            byte[] m = new byte[] { 0x41, 0xE2, 0x82, 0xAC };
            CircularBuffer<byte> cb;
            CircularBuffer<char> cc;
            int bu;
            int cu;
            bool complete;

            cb = new CircularBuffer<byte>(m, 0, 3);
            cc = new CircularBuffer<char>(20);
            d.Convert(cb, cc, true, out bu, out cu, out complete);
            Assert.AreEqual(3, bu);
            Assert.AreEqual(2, cu);
            Assert.AreEqual(0, cb.Length);
            Assert.AreEqual(2, cc.Length);
            Assert.AreEqual('A', cc[0]);
            Assert.AreEqual((char)0xFFFD, cc[1]);
            Assert.IsTrue(complete);

            cb = new CircularBuffer<byte>(m, 0, 3);
            cc = new CircularBuffer<char>(20);
            cc.Produce(19);
            cc.Consume(18);
            d.Convert(cb, cc, true, out bu, out cu, out complete);
            cc.Consume(1);
            Assert.AreEqual(3, bu);
            Assert.AreEqual(2, cu);
            Assert.AreEqual(0, cb.Length);
            Assert.AreEqual(2, cc.Length);
            Assert.AreEqual('A', cc[0]);
            Assert.AreEqual((char)0xFFFD, cc[1]);
            Assert.IsTrue(complete);
        }
开发者ID:DHMechatronicAG,项目名称:SerialPortStream,代码行数:37,代码来源:CircularBufferTest.cs

示例3: CircularBuffer_ReadWrite

        public void CircularBuffer_ReadWrite()
        {
            CircularBuffer<byte> cb = new CircularBuffer<byte>(50);
            cb.Produce(25);
            cb.Consume(25);
            cb.Produce(50);

            byte[] rd = new byte[50];
            Random r = new Random();
            r.NextBytes(rd);

            for (int i = 0; i < rd.Length; i++) {
                cb[i] = rd[i];
            }

            for (int i = 0; i < rd.Length; i++) {
                Assert.AreEqual(rd[i], cb[i], "Index " + i.ToString() + " doesn't match");
            }
        }
开发者ID:DHMechatronicAG,项目名称:SerialPortStream,代码行数:19,代码来源:CircularBufferTest.cs

示例4: CircularBuffer_Revert

        public void CircularBuffer_Revert()
        {
            CircularBuffer<byte> cb = new CircularBuffer<byte>(50);

            // Move the pointer to the middle
            cb.Produce(25);
            cb.Consume(25);

            // Now allocate all space
            cb.Produce(25);
            cb.Produce(25);

            Assert.AreEqual(25, cb.Start);
            Assert.AreEqual(25, cb.ReadLength);
            Assert.AreEqual(25, cb.End);
            Assert.AreEqual(0, cb.WriteLength);

            cb.Revert(5);
            Assert.AreEqual(25, cb.Start);
            Assert.AreEqual(25, cb.ReadLength);
            Assert.AreEqual(20, cb.End);
            Assert.AreEqual(5, cb.WriteLength);

            cb.Revert(20);
            Assert.AreEqual(25, cb.Start);
            Assert.AreEqual(25, cb.ReadLength);
            Assert.AreEqual(0, cb.End);
            Assert.AreEqual(25, cb.WriteLength);

            cb.Revert(20);
            Assert.AreEqual(25, cb.Start);
            Assert.AreEqual(5, cb.ReadLength);
            Assert.AreEqual(30, cb.End);
            Assert.AreEqual(20, cb.WriteLength);
        }
开发者ID:DHMechatronicAG,项目名称:SerialPortStream,代码行数:35,代码来源:CircularBufferTest.cs

示例5: CircularBuffer_ProduceConsume

        public void CircularBuffer_ProduceConsume()
        {
            CircularBuffer<byte> cb = new CircularBuffer<byte>(50);
            Assert.AreEqual(50, cb.Capacity);

            // Initial state
            Assert.AreEqual(0, cb.Start);
            Assert.AreEqual(0, cb.Length);
            Assert.AreEqual(0, cb.ReadLength);
            Assert.AreEqual(0, cb.End);
            Assert.AreEqual(50, cb.Free);
            Assert.AreEqual(50, cb.WriteLength);

            // Test 1: Allocate 50 bytes
            cb.Produce(50);
            Assert.AreEqual(0, cb.Start);
            Assert.AreEqual(50, cb.Length);
            Assert.AreEqual(50, cb.ReadLength);
            Assert.AreEqual(0, cb.End);
            Assert.AreEqual(0, cb.Free);
            Assert.AreEqual(0, cb.WriteLength);

            // Test 2: Free 50 bytes
            cb.Consume(50);
            Assert.AreEqual(0, cb.Start);
            Assert.AreEqual(0, cb.Length);
            Assert.AreEqual(0, cb.ReadLength);
            Assert.AreEqual(0, cb.End);
            Assert.AreEqual(50, cb.Free);
            Assert.AreEqual(50, cb.WriteLength);

            // Test 3: Allocate 25 bytes
            cb.Produce(25);
            Assert.AreEqual(0, cb.Start);
            Assert.AreEqual(25, cb.Length);
            Assert.AreEqual(25, cb.ReadLength);
            Assert.AreEqual(25, cb.End);
            Assert.AreEqual(25, cb.Free);
            Assert.AreEqual(25, cb.WriteLength);

            // Test 4: Free 24 bytes
            cb.Consume(24);
            Assert.AreEqual(24, cb.Start);
            Assert.AreEqual(1, cb.Length);
            Assert.AreEqual(1, cb.ReadLength);
            Assert.AreEqual(25, cb.End);
            Assert.AreEqual(49, cb.Free);
            Assert.AreEqual(25, cb.WriteLength);

            // Test 5: Alocate 49 bytes
            cb.Produce(49);
            Assert.AreEqual(24, cb.Start);
            Assert.AreEqual(50, cb.Length);
            Assert.AreEqual(26, cb.ReadLength);
            Assert.AreEqual(24, cb.End);
            Assert.AreEqual(0, cb.Free);
            Assert.AreEqual(0, cb.WriteLength);

            // Test 6: Reset
            cb.Reset();
            Assert.AreEqual(0, cb.Start);
            Assert.AreEqual(0, cb.Length);
            Assert.AreEqual(0, cb.ReadLength);
            Assert.AreEqual(0, cb.End);
            Assert.AreEqual(50, cb.Free);
            Assert.AreEqual(50, cb.WriteLength);

            // Test 7: Test full wrapping around
            cb.Produce(25);
            cb.Consume(25);
            cb.Produce(50);
            Assert.AreEqual(25, cb.Start);
            Assert.AreEqual(50, cb.Length);
            Assert.AreEqual(25, cb.ReadLength);
            Assert.AreEqual(25, cb.End);
            Assert.AreEqual(0, cb.Free);
            Assert.AreEqual(0, cb.WriteLength);

            // Test 8: Free all data
            cb.Consume(50);
            Assert.AreEqual(25, cb.Start);
            Assert.AreEqual(0, cb.Length);
            Assert.AreEqual(0, cb.ReadLength);
            Assert.AreEqual(25, cb.End);
            Assert.AreEqual(50, cb.Free);
            Assert.AreEqual(25, cb.WriteLength);
        }
开发者ID:DHMechatronicAG,项目名称:SerialPortStream,代码行数:87,代码来源:CircularBufferTest.cs

示例6: CircularBuffer_ReadBlock

        public void CircularBuffer_ReadBlock()
        {
            CircularBuffer<byte> cb = new CircularBuffer<byte>(50);

            // Move the pointer to the middle
            cb.Produce(25);
            cb.Consume(25);

            // Now allocate all space
            cb.Produce(25);
            cb.Produce(25);

            Assert.AreEqual(25, cb.ReadLength);
            Assert.AreEqual(25, cb.GetReadBlock(0));
            Assert.AreEqual(20, cb.GetReadBlock(5));
            Assert.AreEqual(1, cb.GetReadBlock(24));
            Assert.AreEqual(25, cb.GetReadBlock(25));
            Assert.AreEqual(20, cb.GetReadBlock(30));
            Assert.AreEqual(1, cb.GetReadBlock(49));
            Assert.AreEqual(0, cb.GetReadBlock(50));
        }
开发者ID:DHMechatronicAG,项目名称:SerialPortStream,代码行数:21,代码来源:CircularBufferTest.cs

示例7: CircularBuffer_AppendBuffer

        public void CircularBuffer_AppendBuffer()
        {
            CircularBuffer<char> cb1 = new CircularBuffer<char>(20);
            CircularBuffer<char> cb2 = new CircularBuffer<char>(20);

            // Read is one chunk, write is one chunk
            cb2.Produce(3);
            cb2.Append("123456789012345".ToCharArray());
            cb2.Consume(3);

            cb1.Append(cb2);
            Assert.AreEqual(15, cb1.Length);
            Assert.AreEqual(5, cb1.Free);
            Assert.AreEqual("123456789012345", cb1.GetString());

            // Write is one chunk, but read is two chunks
            cb1.Reset();
            cb2.Reset();
            cb2.Produce(15);
            cb2.Consume(14);
            cb2.Append("123456789012345".ToCharArray());
            cb2.Consume(1);

            cb1.Append(cb2);
            Assert.AreEqual(15, cb1.Length);
            Assert.AreEqual(5, cb1.Free);
            Assert.AreEqual("123456789012345", cb1.GetString());

            // Write is two chunks, read is one chunk
            cb1.Reset();
            cb2.Reset();
            cb1.Produce(10);
            cb1.Consume(9);
            cb2.Append("123456789012345".ToCharArray());

            cb1.Append(cb2);
            cb1.Consume(1);
            Assert.AreEqual(15, cb1.Length);
            Assert.AreEqual(5, cb1.Free);
            Assert.AreEqual("123456789012345", cb1.GetString());

            // Write is two chunks, read is two chunks, readlength < writelength
            cb1.Reset();
            cb2.Reset();
            cb1.Produce(10);
            cb1.Consume(9);
            cb2.Produce(15);
            cb2.Consume(14);
            cb2.Append("123456789012345".ToCharArray());
            cb2.Consume(1);

            cb1.Append(cb2);
            cb1.Consume(1);
            Assert.AreEqual(15, cb1.Length);
            Assert.AreEqual(5, cb1.Free);
            Assert.AreEqual("123456789012345", cb1.GetString());

            // Write is two chunks, read is two chunks, readlength > writelength
            cb1.Reset();
            cb2.Reset();
            cb1.Produce(10);
            cb1.Consume(9);
            cb2.Produce(7);
            cb2.Consume(6);
            cb2.Append("123456789012345".ToCharArray());
            cb2.Consume(1);

            cb1.Append(cb2);
            cb1.Consume(1);
            Assert.AreEqual(15, cb1.Length);
            Assert.AreEqual(5, cb1.Free);
            Assert.AreEqual("123456789012345", cb1.GetString());
        }
开发者ID:DHMechatronicAG,项目名称:SerialPortStream,代码行数:73,代码来源:CircularBufferTest.cs

示例8: CircularBuffer_Indexing

        public void CircularBuffer_Indexing()
        {
            CircularBuffer<byte> cb = new CircularBuffer<byte>(50);

            // Write into the array directly
            for (int i = 0; i < cb.Array.Length; i++) {
                cb.Array[i] = (byte)i;
            }
            cb.Produce(50);
            Assert.AreEqual(50, cb.Length);
            Assert.AreEqual(0, cb.Start);

            // Access the array using the indexer
            for (int i = 0; i < cb.Length; i++) {
                Assert.AreEqual(i, cb[i]);
            }

            cb.Consume(25);
            cb.Produce(25);

            // Now the start is in the middle
            Assert.AreEqual(25, cb.Start);
            Assert.AreEqual(50, cb.Length);
            for (int i = 0; i < cb.Length; i++) {
                Assert.AreEqual((i + 25) % 50, cb[i], "Index " + i.ToString());
            }

            for (int i = 0; i < cb.Length; i++) {
                Assert.AreEqual((i + 25) % 50, cb.Array[cb.ToArrayIndex(i)], "Index " + i.ToString());
            }
        }
开发者ID:DHMechatronicAG,项目名称:SerialPortStream,代码行数:31,代码来源:CircularBufferTest.cs

示例9: CircularBuffer_AppendArray

        public void CircularBuffer_AppendArray()
        {
            CircularBuffer<char> cb = new CircularBuffer<char>(20);
            cb.Produce(10);
            cb.Consume(9);

            Assert.AreEqual(1, cb.Length);
            Assert.AreEqual(19, cb.Free);

            cb.Append("ABCDEFGHIJKLMN".ToCharArray(), 0, 14);
            Assert.AreEqual(15, cb.Length);
            Assert.AreEqual(5, cb.Free);

            Assert.AreEqual("ABCDEFGHIJKLMN", cb.GetString(1, 14));
            cb.Consume(15);
            Assert.AreEqual(0, cb.Length);
            Assert.AreEqual(20, cb.Free);

            cb.Append("12345678901234567890".ToCharArray());
            Assert.AreEqual(0, cb.Free);
            Assert.AreEqual(20, cb.Length);
            Assert.AreEqual("12345678901234567890", cb.GetString());
        }
开发者ID:DHMechatronicAG,项目名称:SerialPortStream,代码行数:23,代码来源:CircularBufferTest.cs

示例10: CircularBufferExt_GetStringSimple

        public void CircularBufferExt_GetStringSimple()
        {
            CircularBuffer<char> cb = new CircularBuffer<char>(15);
            for (int i = 0; i < cb.Capacity; i++) {
                cb.Array[i] = (char)((int)'A' + i);
            }

            cb.Produce(10);
            Assert.AreEqual("ABCDEFGHIJ", cb.GetString());
            cb.Consume(5);
            Assert.AreEqual("FGHIJ", cb.GetString());
            cb.Produce(8);
            Assert.AreEqual("FGHIJKLMNOABC", cb.GetString());
            cb.Consume(13);
            Assert.AreEqual("", cb.GetString());

            cb = null;
            Assert.IsNull(cb.GetString());
        }
开发者ID:DHMechatronicAG,项目名称:SerialPortStream,代码行数:19,代码来源:CircularBufferTest.cs

示例11: CircularBufferExt_GetStringOffsetLength

        public void CircularBufferExt_GetStringOffsetLength()
        {
            CircularBuffer<char> cb = new CircularBuffer<char>(15);
            for (int i = 0; i < cb.Capacity; i++) {
                cb.Array[i] = (char)((int)'A' + i);
            }

            cb.Produce(10);
            Assert.AreEqual("ABCDEFGHIJ", cb.GetString(0, 10));
            Assert.AreEqual("ABCDEFGHIJ", cb.GetString(0, 20));
            Assert.AreEqual("", cb.GetString(0, 0));
            Assert.AreEqual("FGHIJ", cb.GetString(5, 5));
            Assert.AreEqual("BCDEFGHIJ", cb.GetString(1, 9));
            Assert.AreEqual("BCDEFGH", cb.GetString(1, 7));
            Assert.AreEqual("", cb.GetString(5, 0));
            cb.Consume(5);
            Assert.AreEqual("FGHIJ", cb.GetString(0, 10));
            Assert.AreEqual("FGHIJ", cb.GetString(0, 5));
            Assert.AreEqual("HIJ", cb.GetString(2, 3));
            Assert.AreEqual("", cb.GetString(5, 0));
            Assert.AreEqual("", cb.GetString(5, 1));
            cb.Produce(8);
            Assert.AreEqual("FGHIJKLMNOABC", cb.GetString(0, 13));
            Assert.AreEqual("FGHIJ", cb.GetString(0, 5));
            Assert.AreEqual("KLMNOABC", cb.GetString(5, 13));
            Assert.AreEqual("KLMNOABC", cb.GetString(5, 8));
            Assert.AreEqual("KLMNO", cb.GetString(5, 5));
            Assert.AreEqual("ABC", cb.GetString(10, 3));
            cb.Consume(13);
            Assert.AreEqual("", cb.GetString(0, 0));
            Assert.AreEqual("", cb.GetString(5, 15));
            Assert.AreEqual("", cb.GetString(10, 20));
            Assert.AreEqual("", cb.GetString(10, 1));

            cb = null;
            Assert.IsNull(cb.GetString(0, 5));
            Assert.IsNull(cb.GetString(10, 0));
            Assert.IsNull(cb.GetString(5, 15));
            Assert.IsNull(cb.GetString(2, 20));
        }
开发者ID:DHMechatronicAG,项目名称:SerialPortStream,代码行数:40,代码来源:CircularBufferTest.cs

示例12: CircularBufferExt_EncoderConvert_Full1

        public void CircularBufferExt_EncoderConvert_Full1()
        {
            Encoding enc = Encoding.GetEncoding("UTF-8");
            Encoder e = enc.GetEncoder();

            char[] c = new char[] { 'A', 'B', '€', 'C' };
            CircularBuffer<byte> cb = new CircularBuffer<byte>(20);
            int bu;
            int cu;
            bool complete;

            cb.Produce(17);
            cb.Consume(3);
            e.Convert(c, 0, 4, cb, false, out cu, out bu, out complete);
            Assert.AreEqual(4, cu);
            Assert.AreEqual(6, bu);
            Assert.AreEqual(20, cb.Length);
            Assert.IsTrue(complete);
            Assert.AreEqual(0x41, cb[14]);
            Assert.AreEqual(0x42, cb[15]);
            Assert.AreEqual(0xE2, cb[16]);
            Assert.AreEqual(0x82, cb[17]);
            Assert.AreEqual(0xAC, cb[18]);
            Assert.AreEqual(0x43, cb[19]);
        }
开发者ID:DHMechatronicAG,项目名称:SerialPortStream,代码行数:25,代码来源:CircularBufferTest.cs

示例13: CircularBufferExt_EncoderConvert

        public void CircularBufferExt_EncoderConvert()
        {
            Encoding enc = Encoding.GetEncoding("UTF-8");
            Encoder e = enc.GetEncoder();

            char[] c = new char[] { 'A', 'B', '€', 'C' };
            CircularBuffer<byte> cb = new CircularBuffer<byte>(20);
            int bu;
            int cu;
            bool complete;

            e.Convert(c, 0, 3, cb, false, out cu, out bu, out complete);
            Assert.AreEqual(3, cu);
            Assert.AreEqual(5, bu);
            Assert.AreEqual(5, cb.Length);
            Assert.IsTrue(complete);

            e.Reset();
            cb.Reset();
            cb.Produce(17);
            cb.Consume(17);
            e.Convert(c, 0, 4, cb, false, out cu, out bu, out complete);
            Assert.AreEqual(4, cu);
            Assert.AreEqual(6, bu);
            Assert.AreEqual(6, cb.Length);
            Assert.IsTrue(complete);
        }
开发者ID:DHMechatronicAG,项目名称:SerialPortStream,代码行数:27,代码来源:CircularBufferTest.cs


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