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


C# CircularBuffer.Append方法代码示例

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


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

示例1: 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

示例2: 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


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